#include using namespace std; using ll = long long; bool deb = 1; /* base:桁数 insert(num): numを挿入. O(log(N)) erase(num): numがあれば一つ削除 O(log(N)) search(num): numがあるか判定 O(log(N)) small_num(num,x) d XOR num next; vector accept; ll c; ll common; Node(ll c_) : c(c_), common(0) { next.assign(2, -1); } }; vector nodes; ll root = 0; Binary_Trie() { nodes.push_back(Node(root)); } void insert(const ll& num) { ll node_id = 0; for (ll b = base; b >= 0; b--) { ll nt = 0; nt = (num & (1ll << b) ? 1 : 0); if (nodes[node_id].next[nt] == -1) { nodes.push_back(Node(nt)); nodes[node_id].next[nt] = nodes.size() - 1; } nodes[node_id].common++; node_id = nodes[node_id].next[nt]; } nodes[node_id].common++; } bool search(const ll& num) { ll node_id = 0; bool EX = 1; for (ll b = base; b >= 0; b--) { ll nt = 0; nt = (num & (1ll << b) ? 1 : 0); if (nodes[node_id].next[nt] == -1||nodes[nodes[node_id].next[nt]].common==0) { EX = 0; break; } node_id = nodes[node_id].next[nt]; } return EX; } void erase(const ll& num) { if (!search(num))return; ll node_id = 0; for (ll b = base; b >= 0; b--) { ll nt = 0; nt = (num & (1ll << b) ? 1 : 0); nodes[node_id].common--; node_id = nodes[node_id].next[nt]; } nodes[node_id].common--; } ll small_num(const ll& p, const ll& x) {//d XOR p= 0; b--) { ll nx = 0, np = 0; nx = (x & (1ll << b) ? 1 : 0); np = (p & (1ll << b) ? 1 : 0); if (nx == 1) { if (nodes[node_id].next[np] != -1) { res += nodes[nodes[node_id].next[np]].common; } if (nodes[node_id].next[1 - np] == -1) { break; } else { node_id = nodes[node_id].next[1 - np]; continue; } } else { if (nodes[node_id].next[np] == -1) { break; } else { node_id = nodes[node_id].next[np]; continue; } } } return res; } ll min_XOR(ll x){ ll res=0; ll node_id = 0; for (ll b = base; b >= 0; b--) { ll nx = 0; nx = (x & (1ll << b) ? 1 : 0); if (nodes[node_id].next[nx] != -1&&nodes[nodes[node_id].next[nx]].common>0) { node_id=nodes[node_id].next[nx]; } else { res+=(1ll<= 0; b--) { if(nodes[node_id].next[0]!=-1&&nodes[nodes[node_id].next[0]].common>K){ node_id=nodes[node_id].next[0]; } else{ res+=(1ll<>N>>K; vector A(N); Binary_Trie B; for(int i=0;i>A[i]; B.insert(A[i]); } ll L=-1,R=4e9; while(R-L>1){ ll M=(R+L)/2; ll cnt=0; if(M!=0)for(int i=0;i