QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#649692#8939. Permutation11d10xyWA 1ms3828kbC++14753b2024-10-18 08:59:102024-10-18 08:59:25

Judging History

This is the latest submission verdict.

  • [2024-10-18 08:59:25]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3828kb
  • [2024-10-18 08:59:10]
  • 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,int res){
   if(l==r)return l;
   int mid=l+r>>1;
   if(!res)res=ask(l,r);
   if(res<=mid){
      if(l==mid)return calc(mid+1,r,0);
      int x=ask(l,mid);
      if(x==res)return calc(l,mid,res);
      else return calc(mid+1,r,0);
   }else{
      if(mid+1==r)return calc(l,mid,0);
      int x=ask(mid+1,r);
      if(x==res)return calc(mid+1,r,res);
      else return calc(mid+1,r,0);
   }
}
void solve(){
   scanf("%d",&n);
   printf("! %d\n",calc(1,n,0)),fflush(stdout);
}
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
Wrong Answer
time: 1ms
memory: 3828kb

input:

3
5
3
2
5
6
6
5
5
4

output:

? 1 5
? 1 3
? 4 5
! 4
? 1 6
? 4 6
? 4 6
? 4 5
! 6

result:

wrong answer Wrong prediction (test case 2)