QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#32854#866. Display of SpringsFroggyguaTL 0ms0kbC++171.4kb2022-05-25 08:44:352022-05-25 08:44:37

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-25 08:44:37]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2022-05-25 08:44:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define N 100010
typedef long long ll;
int n;
int Ask(int a,int b,int k){
	if(!b)return -1;
	cout<<"? "<<a<<' '<<b<<' '<<k<<endl;
	string s;
	cin>>s;
	if(s=="FIRST")return -1;
	if(s=="SECOND")return 1;
	return 0;
}
void Report(int x){
	cout<<"! "<<x<<endl;
}
class Segment_Tree{
	int Len;
	struct node{
		int p;
	}t[N<<2];
	#define ls u<<1
	#define rs u<<1|1
	void _ins(int u,int L,int R,int id){
		if(!id)return;
		if(L==R){
			if(!t[u].p||Ask(id,t[u].p,L)==-1){
				t[u].p=id;
				return;
			}
		}
		int mid=(L+R)>>1;
		if(Ask(id,t[u].p,mid)==-1){
			swap(id,t[u].p);
		}
		if(Ask(t[u].p,id,L)){
			_ins(ls,L,mid,id);
		}
		else if(Ask(t[u].p,id,R)){
			_ins(rs,mid+1,R,id);
		}
	}
	int _query(int u,int L,int R,int pos){
		if(L==R){
			return t[u].p;
		}
		int mid=(L+R)>>1;
		int ans=t[u].p;
		int x=pos<=mid?_query(ls,L,mid,pos):_query(rs,mid+1,R,pos);
		if(Ask(ans,x,pos)==1)ans=x;
		return ans;
	}
public:
	void init(int n,int _len){
		Len=_len;
		for(int i=1;i<=n;++i){
			_ins(1,1,Len,i);
		}
	}
	int Query(int p){
		return _query(1,1,Len,p);
	}
}T;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	T.init(n,100000);
	cout<<"! "<<endl;
	while(true){
		string opt;
		cin>>opt;
		if(opt=="FINISH")break;
		int x;
		cin>>x;
		Report(T.Query(x));
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3
FIRST
SECOND

output:

? 2 1 50000
? 2 1 1
? 3 2 50000

result: