QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#418435 | #8719. 后继 | TLE_Automat | AC ✓ | 425ms | 64120kb | C++20 | 2.6kb | 2024-05-23 13:55:48 | 2024-05-23 13:55:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)((x).size()))
#define lb(x) ((x) & (-(x)))
#define bp(x) __builtin_popcount(x)
#define bpll(x) __builtin_popcountll(x)
#define mkp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
const int MAXN = 4e5 + 10;
struct Trie01 {
int cnt_id;
int tr[MAXN * 30][2];
int ins_id[MAXN * 30];
int pos[30];
void insert(int x, int id) {
int u = 0;
for (int i = 29; i >= 0; i--) {
int dig = (x >> i) & 1;
if (!tr[u][dig]) {
tr[u][dig] = ++cnt_id;
}
u = tr[u][dig];
}
ins_id[u] = id;
}
void dfs(int u, int d) {
int son = 0;
if (tr[u][0]) {
dfs(tr[u][0], d - 1);
son++;
}
if (tr[u][1]) {
dfs(tr[u][1], d - 1);
son++;
}
if (son == 2) {
pos[d] = u;
}
}
void init() {
memset(pos, -1, sizeof(pos));
dfs(0, 29);
}
} T;
void solve() {
int n, q;
cin >> n >> q;
vector a(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> a[i];
T.insert(a[i], i);
}
T.init();
auto ask = [&](int p) -> int {
cout << "? " << p << '\n';
cout.flush();
int res;
cin >> res;
return res;
};
while (q--) {
int ans = 0;
for (int i = 0; i <= 29; i++) {
if (T.pos[i] == -1) {
continue;
}
int x = T.tr[T.pos[i]][0];
int y = T.tr[T.pos[i]][1];
for (int j = i - 1; j >= 0; j--) {
int dig = (ans >> j) & 1;
if (T.tr[x][!dig]) {
x = T.tr[x][!dig];
}
else {
x = T.tr[x][dig];
}
if (T.tr[y][dig]) {
y = T.tr[y][dig];
}
else {
y = T.tr[y][!dig];
}
}
int p = ask(T.ins_id[x]);
if (p != T.ins_id[y]) {
ans |= (1 << i);
}
}
cout << "! " << ans << '\n';
cout.flush();
}
}
int main() {
// ios::sync_with_stdio(false);
// cin.tie(0), cout.tie(0);
int T = 1;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5548kb
input:
5 1 1 2 3 4 5 -1 5 5
output:
? 4 ? 1 ? 1 ! 3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5576kb
input:
1 1 0
output:
! 0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 5748kb
input:
10 10 380864879 387438357 21484978 21099484 375657510 23189485 24467021 379687119 386094773 15156199 3 10 -1 1 2 -1 3 1 10 7 7 -1 7 5 7 1 3 -1 7 10 7 2 2 -1 3 1 10 -1 -1 2 3 1 10 -1 -1 2 3 2 6 4 4 -1 7 10 7 2 2 -1 6 2 6 8 9 -1 3 2 8 9 9 8
output:
? 4 ? 9 ? 3 ? 5 ? 8 ? 3 ! 271581184 ? 4 ? 9 ? 3 ? 5 ? 5 ? 10 ! 296747008 ? 4 ? 9 ? 4 ? 5 ? 8 ? 10 ! 286523392 ? 4 ? 9 ? 4 ? 5 ? 5 ? 6 ! 278134784 ? 4 ? 9 ? 3 ? 5 ? 5 ? 10 ! 28311552 ? 4 ? 9 ? 3 ? 5 ? 5 ? 10 ! 28311552 ? 4 ? 9 ? 3 ? 5 ? 5 ? 10 ! 293601280 ? 4 ? 9 ? 4 ? 5 ? 5 ? 6 ! 278134784 ? 4 ? 9 ?...
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 55ms
memory: 5528kb
input:
100 3000 416322873 449728250 688705913 946343465 16202884 153238658 573284215 724198910 577719053 868106680 951494055 942341618 190594266 331719623 856324110 977865755 151782935 163752541 1565918 870244322 299691610 37854919 198293342 152446496 549402023 869857831 869628458 573984494 162791133 94423...
output:
? 11 ? 58 ? 88 ? 86 ? 75 ? 39 ? 30 ? 75 ? 75 ? 72 ? 65 ? 44 ? 41 ! 184027136 ? 11 ? 58 ? 88 ? 86 ? 75 ? 39 ? 71 ? 66 ? 16 ? 4 ? 32 ? 44 ? 55 ! 445644800 ? 11 ? 58 ? 88 ? 86 ? 75 ? 39 ? 81 ? 75 ? 59 ? 81 ? 99 ? 92 ? 70 ! 145555456 ? 11 ? 58 ? 88 ? 86 ? 75 ? 39 ? 30 ? 75 ? 16 ? 30 ? 65 ? 44 ? 41 ! 179...
result:
ok 3000 numbers
Test #5:
score: 0
Accepted
time: 425ms
memory: 64120kb
input:
400000 3000 406697044 910508999 785308673 89872855 911511537 786066190 569035255 791369083 231783630 373589094 1005702647 785128281 910883228 612232307 428493618 691767283 288087749 380834477 1012471581 807583302 951439706 172399529 651163374 395700503 212381194 528978756 628513589 230244101 1046447...
output:
? 272025 ? 172573 ? 88568 ? 237577 ? 385444 ? 147566 ? 117643 ? 366493 ? 265585 ? 53182 ? 131942 ? 283067 ? 306057 ? 43546 ? 31430 ? 301177 ? 140416 ? 168724 ? 17001 ? 25817 ? 379763 ? 309915 ? 30567 ? 222990 ? 102921 ? 48740 ? 34497 ? 322182 ? 297218 ? 248810 ! 140702791 ? 272025 ? 172573 ? 88568 ?...
result:
ok 3000 numbers
Test #6:
score: 0
Accepted
time: 325ms
memory: 38280kb
input:
400000 3000 49852143 106643027 78538081 13535110 34673790 361240760 358287062 285333122 15578697 106130051 320170693 107023555 72813915 2799162 286900401 787319 332890808 75095435 110215229 74827421 107485420 300695656 71750101 285593446 37660664 397030779 392989831 16018850 14036294 361777963 11269...
output:
? 340849 ? 350183 ? 350183 ? 68204 ? 177973 ? 51316 ? 34470 ? 203258 ? 385276 ? 130531 ? 24221 ? 37723 ? 225258 ? 290260 ? 357305 ? 196125 ? 37678 ? 41556 ? 386535 ? 38445 ! 113099425 ? 340849 ? 350183 ? 350183 ? 207959 ? 225144 ? 207798 ? 247398 ? 4484 ? 382575 ? 123925 ? 44106 ? 396823 ? 27113 ? 4...
result:
ok 3000 numbers
Extra Test:
score: 0
Extra Test Passed