QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#417418#8719. 后继hhhhyfAC ✓306ms83244kbC++201.7kb2024-05-22 18:33:292024-05-22 18:33:31

Judging History

你现在查看的是最新测评结果

  • [2024-05-22 18:33:31]
  • 评测
  • 测评结果:AC
  • 用时:306ms
  • 内存:83244kb
  • [2024-05-22 18:33:29]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(a) a.begin(), a.end()
const int N = 400010, M = 31;

int ch[N * M][2], idx, a[N], pre[N * M];
int ed[N * M], node[M];

void insert (int x, int v) {
    int p = 0;
    for (int i = M - 1, s = 0; i >= 0; i --) {
        int j = x >> i & 1;
        s |= j << i;
        int& u = ch[p][j];
        if (!u) {
            u = ++ idx;
            pre[u] = s;
        }
        if (node[i] == 0 && ch[p][0] && ch[p][1]) {
            node[i] = p;
        }
        p = u;
    }
    ed[p] = v;
}

int query (int x) {
    cout << "? " << x << endl;
    int res;
    cin >> res;
    return res;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n, m;
	cin >> n >> m;
	
	for (int i = 1; i <= n; i ++) {
	    int x;
	    cin >> x;
	    a[i] = x;
	    insert(x, i);
	}
	
	while (m --) {
	    int ans = 0;
	    for (int i = 0; i < M; i ++) {
	        int& x = node[i];
	        if (!x) continue;
	        
	        function<int(int, int)> get_max = [&](int p, int j) {
	            if (j == -1) {
	                return ed[p];
	            }
	            if (!ch[p][1]) {
	                return get_max(ch[p][0], j - 1);
	            }
	            if (!ch[p][0]) {
	                return get_max(ch[p][1], j - 1);
	            }
	            if (ans >> j & 1 ^ 1) {
	                return get_max(ch[p][1], j - 1);
	            }
	            return get_max(ch[p][0], j - 1);
	        };
	        
	        int p = get_max(ch[x][0], i - 1);
	        int q = query(p);
	        if (q == -1 || (a[q] ^ pre[ch[x][1]]) >= (1 << i)) {
	            ans |= 1 << i;
	        }
	    }
	    cout << "! " << ans << endl;
	}
    
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3760kb

input:

5 1
1 2 3 4 5
1
5
5

output:

? 2
? 1
? 1
! 3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3720kb

input:

1 1
0

output:

! 0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 1ms
memory: 3680kb

input:

10 10
380864879 387438357 21484978 21099484 375657510 23189485 24467021 379687119 386094773 15156199
3
4
-1
1
2
-1
3
4
10
7
7
-1
7
10
7
1
3
-1
7
-1
7
2
2
-1
3
4
10
-1
-1
2
3
4
10
-1
-1
2
3
7
6
4
4
-1
7
-1
7
2
2
-1
6
7
6
8
9
-1
3
7
8
9
9
8

output:

? 4
? 6
? 3
? 5
? 8
? 3
! 271581184
? 4
? 6
? 3
? 5
? 5
? 10
! 296747008
? 4
? 6
? 4
? 5
? 8
? 10
! 286523392
? 4
? 6
? 4
? 5
? 5
? 6
! 278134784
? 4
? 6
? 3
? 5
? 5
? 10
! 28311552
? 4
? 6
? 3
? 5
? 5
? 10
! 28311552
? 4
? 6
? 3
? 5
? 5
? 10
! 293601280
? 4
? 6
? 4
? 5
? 5
? 6
! 278134784
? 4
? 6
?...

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 18ms
memory: 3552kb

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
? 26
? 27
? 17
? 17
? 7
? 72
? 78
? 19
? 44
? 41
! 184027136
? 11
? 58
? 88
? 26
? 27
? 17
? 17
? 7
? 4
? 78
? 55
? 44
? 55
! 445644800
? 11
? 58
? 88
? 26
? 27
? 17
? 24
? 28
? 81
? 78
? 57
? 92
? 70
! 145555456
? 11
? 58
? 88
? 26
? 27
? 17
? 17
? 7
? 30
? 78
? 77
? 44
? 41
! 179914...

result:

ok 3000 numbers

Test #5:

score: 0
Accepted
time: 306ms
memory: 83244kb

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:

? 65503
? 24195
? 14712
? 1005
? 15989
? 5820
? 5242
? 1687
? 248
? 1598
? 1103
? 675
? 207732
? 247
? 28500
? 94348
? 329246
? 82156
? 61401
? 273471
? 252486
? 111865
? 40818
? 120318
? 198723
? 6536
? 137120
? 297218
? 297218
? 248810
! 140702791
? 65503
? 24195
? 14712
? 1005
? 15989
? 5820
? 52...

result:

ok 3000 numbers

Test #6:

score: 0
Accepted
time: 221ms
memory: 47896kb

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:

? 1487
? 1127
? 1203
? 245855
? 211932
? 10832
? 137541
? 51
? 19950
? 271185
? 250988
? 135732
? 386535
? 383297
? 386535
? 174147
? 390588
? 179870
? 38445
? 38445
! 113099425
? 1487
? 1127
? 1203
? 663
? 275314
? 394988
? 181985
? 188038
? 337382
? 393790
? 347196
? 284174
? 10788
? 276434
? 1891...

result:

ok 3000 numbers

Extra Test:

score: 0
Extra Test Passed