Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- map<pair<int,int>,int> cod;
- int idx;
- set<int> ret;
- int t[1<<21];
- class Tree
- {
- public:
- Tree() { memset(t,-1,sizeof(t)); }
- void insert(int k)
- {
- int node = 1;
- while (t[node] != -1)
- {
- int p = (t[node]<k);
- node = 2*node+p;
- }
- t[node] = k;
- }
- int code(int node)
- {
- if (t[node] == -1) return -1;
- if (t[2*node] == -1 && t[2*node+1] == -1) return 0;
- if (cod[make_pair(code(2*node),code(2*node+1))])
- return cod[make_pair(code(2*node),code(2*node+1))];
- return cod[make_pair(code(2*node),code(2*node+1))] = idx++;
- }
- };
- int main()
- {
- int N,K; cin >> N >> K;
- idx = 1;
- for (int i = 0; i < N; i++)
- {
- Tree t;
- for (int j = 0; j < K; j++)
- {
- int X; cin >> X;
- t.insert(X);
- }
- ret.insert(t.code(1));
- }
- cout << ret.size() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment