https://codeforces.com/contest/1658/problem/D2
int l, r; int son[M][2], idx; int a[N]; void init() {//初始化** idx = 0; son[0][0] = son[0][1] = 0; } void insert(int x) { int p = 0; for (int i = 30; ~i; i --) { int &v = son[p][x >> i & 1]; if (!v) { son[idx + 1][0] = son[idx + 1][1] = 0;//初始化***** v = ++ idx; } p = v; } } int findmax(int x) { int p = 0, ans = 0; for (int i = 30; ~i; i --) { int v = x >> i & 1; if (son[p][!v]) { ans += 1 << i; p = son[p][!v]; } else p = son[p][v]; } return ans; } int findmin(int x) { int p = 0, ans = 0; for (int i = 30; ~i; i --) { int v = x >> i & 1; if (son[p][v]) p = son[p][v]; else { ans += 1 << i; p = son[p][!v]; } } return ans; } void solve() { cin >> l >> r; init(); for (int i = l; i <= r; i ++) cin >> a[i], insert(a[i]); for (int i = l; i <= r; i ++) { int x = a[i] ^ l; if (findmin(x) == l && findmax(x) == r) { cout << x << endl; return; } } }
标签:初始化,idx,int,son,ans,模板,字典 From: https://www.cnblogs.com/Leocsse/p/16855662.html