求助玄关
  • 板块灌水区
  • 楼主hwc2011
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/12/12 10:36
  • 上次更新2024/12/12 18:02:23
查看原帖
求助玄关
1313003
hwc2011楼主2024/12/12 10:36

一道交互题
程序:

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,ans[100005],tot;
void doit(int l,int r,int cnt){
	int mid=l+r>>1,sum;
	printf("1 %lld %lld\n",l,mid);
	fflush(stdout);
	scanf("%lld",&sum);
	if(mid-l+1==sum) for(int i=l;i<=mid;i++) ans[++tot]=i;
	else if(sum>0) doit(l,mid,sum);
	if(r-mid==cnt-sum) for(int i=mid+1;i<=r;i++) ans[++tot]=i;
	else if(cnt-sum>0) doit(mid+1,r,cnt-sum);
}
signed main(){
	scanf("%lld",&n);
	printf("1 1 %lld\n",n);
	fflush(stdout);
	int sum;
	scanf("%lld",&sum);
	doit(1,n,sum);
	printf("2 %lld ",tot);
	fflush(stdout);
	for(int i=1;i<=tot;i++){
		printf("%lld ",ans[i]);
		fflush(stdout);
	}
}

SPJ:

#include "testlib.h"
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char** argv){
	registerTestlibCmd(argc, argv);
	long long n=inf.readLong(1ll,1000000000000000000ll);
	int m=inf.readInt(1,100000)/*,cnt=inf.readInt()*/;
	long long a[m+5];
	for(int i=1;i<=m;i++) a[i]=inf.readLong(1ll,1000000000000000000ll);
	a[m+1]=1000000000000114514;
	cout.flush();
	int pos=0;
	while(1){
//		if(pos>2*cnt+100) quitf(_wa,"The detector is broken");
		int s=ouf.readInt(1,2); 
		if(s==1){
			long long l=ouf.readLong(1ll,1000000000000000000ll),r=ouf.readLong(1ll,1000000000000000000ll);
			if(l>r) quitf(_wa,"l is bigger than r");
			if(l>a[m]||r<a[1]){
				printf("0\n");
				cout.flush();
			}
			l=max(l,a[1]);
			r=min(r,a[m]);
			int ll=lower_bound(a+1,a+1+m,l)-(a+1);
			int rr=upper_bound(a+1,a+2+m,r)-(a+2);
			printf("%d\n",max(0,rr-ll+1));
			cout.flush();
			pos++;
		}
		else{
			int nn=ouf.readInt(1,100000);
			if(n!=nn) quitf(_wa,"The number of defective products is wrong");
			for(int i=1;i<=n;i++){
				long long b=ouf.readLong(1ll,1000000000000000000ll);
				if(b!=a[i]) quitf(_wa,"The id of defective products is wrong");
			}
			/*if(pos<=cnt+100)*/ quitf(_ok,"You get 100 percent of the points and you get answer with %d questions",pos); 
//			else quitp(0.6,"You get 60 percent of the points");
		}
	}
}

错误:

Time Limit Exceeded.wrong output format Unexpected end of file - int32 expected
2024/12/12 10:36
加载中...