QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479323#8719. 后继lococTL 59ms5700kbC++171.9kb2024-07-15 16:24:042024-07-15 16:24:04

Judging History

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

  • [2024-07-15 16:24:04]
  • 评测
  • 测评结果:TL
  • 用时:59ms
  • 内存:5700kb
  • [2024-07-15 16:24:04]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
// #define int ll
#define lp (p<<1)
#define rp (p<<1|1)
const int N = 4e5 + 100 , M = 3e5 + 100;
const int INF = 1e18,MOD = 998244353;
ll qpow(ll x,ll p){ll res=1;while(p){if(p&1)res=res*x%MOD;x=x*x%MOD;p>>=1;}return res;}
ll inv(ll x){return qpow(x,MOD-2);}
int n, m;
int tr[ N ], next[ N ][ 2 ];
int a[ N ], tot;
int has[ 35 ];

void add( int x, int pos ){
	int p = 0;
	for( int i = 30 ; i >= 0 ; i -- ){
		if( next[ p ][ x >> i & 1 ] == 0 ){
			next[ p ][ x >> i & 1 ] = ++ tot;
		}
		if( next[ p ][ 1 ] && next[ p ][ 0 ] ) has[ i ] = p;
		p = next[ p ][ x >> i & 1 ];
		tr[ p ] = pos;
	}	
}

int getmax( int p, int ans, int w ){
	w--;
	while( next[ p ][ 0 ] || next[ p ][ 1 ] ){
		if (next[p][((ans >> w) & 1) ^ 1])
			p = next[p][((ans >> w) & 1) ^ 1];
		else
			p = next[p][((ans >> w) & 1) ^ 0];
		w--;
	}
	return tr[ p ];
}

int getmin( int p, int ans, int w ){
	w--;
	while( next[ p ][ 0 ] || next[ p ][ 1 ] ){
		if (next[p][((ans >> w) & 1) ^ 0])
			p = next[p][((ans >> w) & 1) ^ 0];
		else
			p = next[p][((ans >> w) & 1) ^ 1 ];
		w--;
	}
	return tr[ p ];
}

int ask( int x ){
	int ans = 0;
	std::cout<<"? "<<x<<std::endl;
	std::cin>>ans;
	return ans;
}

void solve(){
	std::cin>>n>>m;
	for( int i = 1 ; i <= n ; i ++ ) std::cin>>a[ i ];

	for( int i = 1 ; i <= n ; i ++ ){
		add( a[ i ], i );
	}

	while( m-- ){
		int ans = 0;
		for( int i = 0 ; i <= 30 ; i ++ ){
			if( has[ i ] == 0 ) continue;
			//  如果询问左边最大的 == 右边最小的,说明没变
			if( ask( getmax( next[ has[ i ] ][ 0 ], ans, i ) ) == getmin( next[ has[ i ] ][ 1 ], ans, i ) ) continue;
			ans += 1 << (i);
		}
		std::cout<<"! "<<ans<<std::endl;
	}
}


signed main(){
	std::ios::sync_with_stdio(0);std::cin.tie(0);std::cout.tie(0);
	// int t;std::cin>>t;
	// while(t--)
		solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

1 1
0

output:

! 0

result:

ok 1 number(s): "0"

Test #3:

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

input:

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

output:

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

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 59ms
memory: 5640kb

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
? 85
? 88
? 86
? 87
? 62
? 99
? 37
? 37
? 65
? 65
? 44
? 41
! 184027136
? 11
? 85
? 88
? 86
? 87
? 62
? 99
? 60
? 100
? 32
? 32
? 44
? 55
! 445644800
? 11
? 85
? 88
? 86
? 87
? 62
? 99
? 37
? 99
? 65
? 99
? 92
? 70
! 145555456
? 11
? 85
? 88
? 86
? 87
? 62
? 99
? 37
? 99
? 65
? 65
? 44
? 41
! 1...

result:

ok 3000 numbers

Test #5:

score: -100
Time Limit Exceeded

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:


result: