// Code By CloudySky #include<bits/stdc++.h> // #define int long long namespace IO { inlineintread(){ int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();} while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = getchar(); return x * f; } voidprint_n(int x){ if (x > 9) print_n(x / 10); putchar(x % 10 + '0'); } inlinevoidprint(int x, char s = '\n'){ if (x < 0) putchar('-'), x = -x; print_n(x), putchar(s); } } // namespace IO usingnamespace IO; voidopenfile(); constint Maxn = 4e5 + 10; usingnamespace std; int trie[Maxn][2], tot; voidinsert(int x){ for (int i = 18, p = 1; ~i; --i) { int ch = (x >> i) & 1; if (!trie[p][ch]) trie[p][ch] = ++tot; p = trie[p][ch]; } } intask_max(int x, int res = 0){ for (int i = 18, p = 1; ~i; --i) { int ch = (x >> i) & 1; if (trie[p][!ch]) res += (1 << i), p = trie[p][!ch]; else p = trie[p][ch]; } return res; } intask_min(int x, int res = 0){ for (int i = 18, p = 1; ~i; --i) { int ch = (x >> i) & 1; if (trie[p][ch]) p = trie[p][ch]; else res += (1 << i), p = trie[p][!ch]; } return res; } int a[Maxn]; voidwork(){ tot = 1; int l = read(), r = read(), ans = 0; for (int i = l; i <= r; ++i) insert(a[i] = read()); for (int i = l; i <= r; ++i) { if (ask_max(a[i] ^ l) == r && ask_min(a[i] ^ l) == l) ans = a[i] ^ l; } print(ans); for (int i = 1; i <= tot; ++i) trie[i][0] = trie[i][1] = 0; } signedmain(){ // openfile(); int t = read(); while (t--) work(); return0; } voidopenfile(){ #ifndef ONLINE_JUDGE freopen("in.in", "r", stdin); freopen("out.out", "w", stdout); #endif }
E. Gojou and Matrix Game
题目描述
给定一个 n×n 带权棋盘,和一个数 k。代表距离(曼哈顿)对方上一步下的棋必须大于 k 。可以在之前下过棋的地方再次下棋并且获得分数。