ILE求调
查看原帖
ILE求调
1051983
bo_od楼主2025/7/28 14:16

帮@tasho11y问的。 \

#include<bits/stdc++.h>
using namespace std;
long long n,k,ans,kk;
void solve(){
	cin>>n>>k;
	ans=0;
	if(n==k){
		cout<<"?1"<<endl;
		cout.flush();
		cin>>ans;
		if(ans==-1)exit(0);
	}
	else{
		int i;
		for(i=1;i<=n-k+1;i+=k){
			cout<<"?"<<i<<endl;
			cout.flush();
			cin>>kk;
			if(kk==-1)exit(0);
			ans^=kk;
		}
		if(n%k!=0){
			cout<<"?"<<i-k+(n%k)/2<<endl;
			cout.flush();
			cin>>kk;
			if(kk==-1)exit(0);
			ans^=kk;
			cout<<"?"<<n-k+1<<endl;
			cout.flush();
			cin>>kk;
			if(kk==-1)exit(0);
			ans^=kk;
		}
	}
	cout<<"!"<<ans<<endl;
	cout.flush();
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	long long T;cin>>T;
	while(T--)solve();
	return 0;
}

感觉是交互库那一段没写对。

2025/7/28 14:16
加载中...