QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#649677#8939. Permutation11d10xyTL 0ms0kbC++14521b2024-10-18 08:50:562024-10-18 08:50:57

Judging History

This is the latest submission verdict.

  • [2024-10-18 08:50:57]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 0kb
  • [2024-10-18 08:50:56]
  • Submitted

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;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

3
5
1
2
5
3

output:

? 1 2
? 1 3
? 4 5
? 1 5

result: