QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#469322#8719. 后继JEdwardAC ✓405ms163008kbC++171.8kb2024-07-09 17:32:172024-07-09 17:32:17

Judging History

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

  • [2024-07-09 17:32:17]
  • 评测
  • 测评结果:AC
  • 用时:405ms
  • 内存:163008kb
  • [2024-07-09 17:32:17]
  • 提交

answer

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define int long long
//#define endl '\n'
#define lowbit(x) (x)&(-x)
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define ls(x) (x<<1)
#define rs(x) (x<<1|1) 
#define here system("pause")
using namespace std;

const int N = 4e5+5;
const int mod = 1e9+7;
const int INF = 1e15+7;
const double eps = 1e-6;
inline int pow(int a, int b, int p){ int res = 1%p; while(b){ if(b&1) res=res*a%p; a=a*a%p, b>>=1;} return res;}
inline int inv(int a, int p){ return pow(a,p-2,p)%p;}
int n, m, tot;
int a[N], ch[N*31][2], dep[N*31], id[N*31];
int wh[31] = {-1};//用于存储具有两个不同子节点(即0和1分支都存在)的节点的索引,如果不存在则为-1。

inline int ask(int x){
	cout << "? " << x << endl;
	cin >> x;
	return x;
}

inline int insert(int x){
	int p = 0;
	for(int i=29;i>=0;i--){
		int j = x>>i&1;
		if(!ch[p][j]) ch[p][j] = ++tot, dep[p] = i;
		p = ch[p][j];
	}
	return p;
}

inline void sol(){
	cin >> n >> m;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		int p = insert(a[i]);
		id[p] = i;
	}
	
	for(int i=0;i<30;i++) wh[i] = -1;
	
	for(int i=0;i<tot;i++){
		if(ch[i][0] && ch[i][1]) wh[dep[i]] = i;
	}
	
	while(m--){
		int res = 0;
		for(int i=0;i<30;i++){
			if(~wh[i]){
				int l = ch[wh[i]][0], r = ch[wh[i]][1];
				for(int j=i-1;j>=0;j--){
					if(ch[l][!((res>>j)&1)]) l = ch[l][!((res>>j)&1)];
					else l = ch[l][(res>>j)&1];
					
					if(ch[r][(res>>j)&1]) r = ch[r][(res>>j)&1];
					else r = ch[r][!((res>>j)&1)];
				}
				
				if(ask(id[l])!=id[r]){
					res |= 1<<i;
				}
			}
		}
		cout << "! " << res << endl;
	} 
}


signed main(){
	IOS;
	int tc = 1;
	while(tc--){
		sol();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7724kb

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: 7684kb

input:

1 1
0

output:

! 0

result:

ok 1 number(s): "0"

Test #3:

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

input:

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

output:

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

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 70ms
memory: 7736kb

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
? 62
? 99
? 51
? 65
? 41
? 19
? 44
? 41
! 184027136
? 11
? 58
? 88
? 86
? 75
? 62
? 99
? 51
? 32
? 41
? 55
? 44
? 55
! 445644800
? 11
? 58
? 88
? 86
? 75
? 62
? 99
? 51
? 65
? 41
? 57
? 92
? 70
! 145555456
? 11
? 58
? 88
? 86
? 75
? 62
? 99
? 51
? 65
? 41
? 77
? 44
? 41
! 17...

result:

ok 3000 numbers

Test #5:

score: 0
Accepted
time: 405ms
memory: 163008kb

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:

? 324118
? 354061
? 367950
? 389615
? 396724
? 394970
? 397048
? 395931
? 399726
? 397704
? 398644
? 399974
? 395304
? 396852
? 305853
? 334550
? 222082
? 62854
? 221815
? 268311
? 133345
? 197826
? 126445
? 394374
? 344544
? 371824
? 34497
? 304394
? 297218
? 248810
! 140702791
? 324118
? 354061
? ...

result:

ok 3000 numbers

Test #6:

score: 0
Accepted
time: 371ms
memory: 96824kb

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:

? 399108
? 399890
? 399208
? 389830
? 279367
? 294436
? 274594
? 139961
? 362951
? 214558
? 255424
? 3814
? 169795
? 251886
? 29307
? 37678
? 37678
? 386535
? 386535
? 38445
! 113099425
? 399108
? 399890
? 399208
? 384877
? 336455
? 228542
? 96287
? 160598
? 64854
? 303272
? 136187
? 292072
? 334176...

result:

ok 3000 numbers

Extra Test:

score: 0
Extra Test Passed