说句闲话:研究珂学的最好方法是
查看原帖
说句闲话:研究珂学的最好方法是
545835
TTpandaS楼主2024/7/23 09:05

求助

样例第三组数据的隐藏数组 aa 是 6 3 1 3 6 1 2 1,在本地按照这个与代码手动交互都没问题,但是提交CF就会输出-1

#include<bits/stdc++.h>
using namespace std;
int T;
int n,k;
signed main(){
	cin>>T;
	cout.flush();
	while(T--){
		cin>>n>>k;
		cout.flush();
		int maxn=-1;
		for(int i=n;i>=1;i--){
			cout<<"? "<<1<<' '<<i*n<<endl;
			cout.flush();
			int p;
			cin>>p;
			cout.flush();
			if(p!=n+1){
				maxn=i;
				break;
			}
		}
//		cerr<<"maxn:"<<maxn<<endl;
		bool flag=0;
		for(int i=1;i<=n/k;i++){
			int now=1;
			int tot=0;
			while(now<=n&&tot<k){
				cout<<"? "<<now<<' '<<i*maxn<<endl;
				cout.flush();
				int p;
				cin>>p;			
				cout.flush();
				if(p==n+1){
					break;
				}	
				tot++;
				now=p+1;
			}
			if(now==n+1&&tot==k){
				cout<<"! "<<i*maxn<<endl;
				cout.flush();
				flag=1;
				break;
			}
		}
		if(!flag){
			cout<<"! -1\n";
			cout.flush();
		}
	}
	return 0;
}
2024/7/23 09:05
加载中...