QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#649696#8939. Permutation11d10xyWA 57ms3920kbC++14751b2024-10-18 09:00:502024-10-18 09:00:50

Judging History

This is the latest submission verdict.

  • [2024-10-18 09:00:50]
  • Judged
  • Verdict: WA
  • Time: 57ms
  • Memory: 3920kb
  • [2024-10-18 09:00:50]
  • 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(l,mid,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: 100
Accepted
time: 1ms
memory: 3836kb

input:

3
5
3
2
5
6
6
5
3
1
4
3
3

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 57ms
memory: 3920kb

input:

10000
10
2
2
3
5
10
10
10
9
7
7
10
5
1
10
9
6

output:

? 1 10
? 1 5
? 1 3
? 4 5
! 4
? 1 10
? 6 10
? 9 10
? 6 8
? 6 7
! 6
? 1 10
? 1 5
? 6 10
? 9 10
? 6 8
? 6 7

result:

wrong answer Too many queries , n = 10 , now_q 6 (test case 3)