QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#32858 | #866. Display of Springs | Froggygua | RE | 4ms | 3692kb | C++17 | 1.4kb | 2022-05-25 08:51:49 | 2022-05-25 08:51:52 |
Judging History
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;
if(!a)return 1;
--a,--b;
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){
--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)==1){
_ins(ls,L,mid,id);
}
else{
_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: 100
Accepted
time: 1ms
memory: 3592kb
input:
3 FIRST FIRST FIRST SECOND QUESTION 2 SECOND QUESTION 6 FIRST FINISH
output:
? 1 0 50000 ? 1 0 1 ? 2 1 50000 ? 2 1 1 ! ? 2 1 2 ! 1 ? 2 1 6 ! 2
result:
ok Correct answer
Test #2:
score: 0
Accepted
time: 4ms
memory: 3692kb
input:
6 FIRST EQUAL FIRST SECOND FIRST SECOND FIRST SECOND FIRST SECOND FIRST SECOND FIRST SECOND FIRST SECOND FIRST SECOND FIRST SECOND FIRST SECOND QUESTION 1 SECOND SECOND SECOND SECOND QUESTION 2 EQUAL SECOND SECOND SECOND QUESTION 3 FIRST EQUAL SECOND SECOND QUESTION 4 FIRST FIRST EQUAL SECOND QUESTI...
output:
? 1 0 50000 ? 1 0 1 ? 2 1 50000 ? 2 1 1 ? 3 2 50000 ? 3 2 1 ? 2 1 25000 ? 2 1 1 ? 4 3 50000 ? 4 3 1 ? 3 2 25000 ? 3 2 1 ? 2 1 12500 ? 2 1 1 ? 5 4 50000 ? 5 4 1 ? 4 3 25000 ? 4 3 1 ? 3 2 12500 ? 3 2 1 ? 2 1 6250 ? 2 1 1 ! ? 2 1 1 ? 3 1 1 ? 4 1 1 ? 5 1 1 ! 1 ? 2 1 2 ? 3 2 2 ? 4 2 2 ? 5 2 2 ! 2 ? 2 1 3...
result:
ok Correct answer
Test #3:
score: -100
Runtime Error
input:
326 SECOND FIRST SECOND SECOND FIRST SECOND FIRST SECOND SECOND SECOND SECOND SECOND FIRST FIRST SECOND FIRST SECOND FIRST SECOND SECOND SECOND FIRST SECOND SECOND SECOND FIRST SECOND FIRST FIRST FIRST FIRST FIRST FIRST FIRST SECOND FIRST SECOND FIRST FIRST FIRST FIRST FIRST SECOND FIRST FIRST FIRST...
output:
? 1 0 50000 ? 0 1 1 ? 2 0 50000 ? 0 2 1 ? 3 0 50000 ? 3 0 1 ? 0 2 25000 ? 0 2 1 ? 4 3 50000 ? 3 4 1 ? 4 0 25000 ? 0 4 1 ? 4 2 12500 ? 4 2 1 ? 5 3 50000 ? 3 5 1 ? 5 1 75000 ? 1 5 50001 ? 6 3 50000 ? 3 6 1 ? 6 0 25000 ? 0 6 1 ? 7 3 50000 ? 3 7 1 ? 7 0 25000 ? 0 7 1 ? 7 6 37500 ? 6 7 25001 ? 8 3 50000 ...