题解:「TFXOI R1」我欲于群山之巅
验题人题解。
每次操作的具体参数我们无法知道,但也不关心。知道高度的相对大小就够了。
考虑线段树。
设当前区间为
按区间修改操作找到
因为交互库实现常数大,所以增加剪枝,若
时间
code:
#include<bits/stdc++.h>
#define ll long long
#define gc getchar
#define pc putchar
#define sc scanf
#define pr printf
#define fu(v,s,e) for(int v=s;v<=(e);v++)
#define fd(v,s,e) for(int v=s;v>=(e);v--)
#define ciallo cerr<<"Ciallo~\n"
#define fuck cerr<<"Fuck you\n"
#define ___ cerr<<"----------------\n"
#define ___2 cerr<<"================\n"
#define mem(a,x) memset(a,x,sizeof(a))
#define itn int
#ifdef DEBUG
#define debug(...) __VA_ARGS__
#else
#define debug(...)
#endif
using namespace std;
#ifdef INFO
struct __info{~__info(){cerr<<'\n';___;cerr<<"Time: "<<1000.0*clock()/CLOCKS_PER_SEC<<" ms.\n";FILE* mem=fopen("/proc/self/status","r");char str[128];while(fgets(str,128,mem)!=NULL) if(strncmp(str,"VmRSS:",6)==0){cerr<<"Memory: "<<atoi(str+6)/1024.0<<" MB.\n";break;}}}_info_tmp;
#endif
inline int in(){char c=gc();int x=0,f=1;while((c<'0'||c>'9')&&c!='-') c=gc();if(c=='-') f=-1,c=gc();while(c>='0'&&c<='9') x=x*10+c-'0',c=gc();return x*f;}
int n,m,k;
int tr[400005];
#define lc (i<<1)
#define rc (lc|1)
void build(int i,int l,int r){
tr[i]=r;
if(l==r) return;
int m=(l+r)>>1;
build(lc,l,m);
build(rc,m+1,r);
}
void modify(int i,int l,int r,int L,int R){
if(L<=l&&r<=R) return;
int m=(l+r)>>1;
itn tlc=tr[lc],trc=tr[rc];
if(L<=m) modify(lc,l,m,L,R);
if(R>m) modify(rc,m+1,r,L,R);
if(tr[lc]==tlc&&tr[rc]==trc&&((tlc<L&&trc>R)||(tlc>=L&&trc<=R))) return; //剪枝
pr("? %d %d\n",tr[lc],tr[rc]);
fflush(stdout);
int res=in();
if(res) tr[i]=tr[lc];
else tr[i]=tr[rc];
}
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n=in(),m=in(),k=in();
build(1,1,n);
while(m--){
int l=in(),r=in();
modify(1,1,n,l,r);
pr("! %d\n",tr[1]);
fflush(stdout);
}
return 0;
}