QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#211200 | #866. Display of Springs | 275307894a | TL | 0ms | 0kb | C++14 | 1.5kb | 2023-10-12 11:47:44 | 2023-10-12 11:48:33 |
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e5+5,M=N*4,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-6;const ll INF=1e18+7;mt19937 rnd(263082);
int n,k=1e5;
int merge(int x,int y,int w){
if(x==-1) return y;if(y==-1) return x;
cout<<"? "<<x<<' '<<y<<' '<<w<<endl;
string s;cin>>s;
return s=="FIRST"?x:y;
}
namespace Tree{
#define ls v<<1
#define rs v<<1|1
int id[M];
void BD(){Me(id,-1);}
void Add(int x,int l=1,int r=k,int v=1){
if(l==r) {id[v]=merge(id[v],x,l);return;}int m=l+r>>1;
if(merge(x,id[v],m)==x) swap(x,id[v]);
merge(x,id[v],l)^x?Add(x,m+1,r,rs):Add(x,l,m,ls);
}
int qry(int x,int l=1,int r=k,int v=1){
if(l==r) return id[v];int m=l+r>>1;
return merge(id[v],x<=m?qry(x,l,m,ls):qry(x,m+1,r,rs),x);
}
}
void Solve(){
int i,j;cin>>n;Tree::BD();
for(i=1;i<=n;i++) Tree::Add(i);
cout<<"!"<<endl;
while(1){
string s;cin>>s;
if(s=="FINISH") break;
int x;cin>>x;
cout<<"! "<<Tree::qry(x)<<endl;
}
}
int main(){
// freopen("1.in","r",stdin);
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
3 FIRST FIRST
output:
? 2 1 50000 ? 1 2 1 ? 3 2 50000