QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#649677 | #8939. Permutation | 11d10xy | TL | 0ms | 0kb | C++14 | 521b | 2024-10-18 08:50:56 | 2024-10-18 08:50:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
inline int ask(int l,int r){
printf("? %d %d\n",l,r);fflush(stdout);
int x;scanf("%d",&x);return x;
}
int calc(int l,int r){
if(l==r)return l;
int mid=l+r>>1,x=calc(l,mid),y=calc(mid+1,r),res=ask(l,r);
if(res==x)return y;
if(res==y)return x;
if(l<=res&&res<=mid)return x;
else return y;
}
void solve(){
scanf("%d",&n);
printf("! %d\n",calc(1,n));
}
int main(){
int T;for(scanf("%d",&T);T--;)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3 5 1 2 5 3
output:
? 1 2 ? 1 3 ? 4 5 ? 1 5