QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#606628#8939. Permutationucup-team902#WA 28ms3912kbC++17894b2024-10-03 11:04:352024-10-03 11:04:35

Judging History

This is the latest submission verdict.

  • [2024-10-03 11:04:35]
  • Judged
  • Verdict: WA
  • Time: 28ms
  • Memory: 3912kb
  • [2024-10-03 11:04:35]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const double val=0.618;
int n;
int query(int l,int r){
    if(l==r) return -1;
    printf("? %d %d\n",l,r); fflush(stdout);
    int x; scanf("%d",&x);
    return x;
}
void work(int l,int r,int x){
    if(l==r){
        printf("! %d\n",x); fflush(stdout);
        return;
    }
    if(r==l+1){
        printf("! %d\n",l+r-x); fflush(stdout);
        return;
    }
    int mid=l+r>>1,len=round(val*(r-l+1));
    if(x<=mid){
        int y=query(l,l+len-1);
        if(x==y) work(l,l+len-1,x);
        else work(l+len,r,query(l+len,r));
    }
    else{
        int y=query(r-len+1,r);
        if(x==y) work(r-len+1,r,x);
        else work(l,r-len,query(l,r-len));
    }
}
void solve(){
    scanf("%d",&n);
    work(1,n,query(1,n));
}
int main(){
    int t; scanf("%d",&t);
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3824kb

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: 0
Accepted
time: 28ms
memory: 3912kb

input:

10000
10
2
2
2
1
3
10
10
10
7
5
10
5
1
10
9
8
10
4
4
4
4
10
10
6
3
4
2
10
3
3
3
4
2
10
1
5
9
10
7
10
1
3
8
8
10
2
4
9
9
10
3
3
3
3
10
4
1
7
8
9
10
8
7
1
2
4
10
4
1
9
9
10
7
7
7
8
6
10
5
1
7
8
10
10
8
8
8
7
9
10
2
2
1
5
10
6
6
8
10
10
1
3
8
8
10
7
9
4
4
10
7
8
4
4
10
3
4
7
8
10
10
4
4
4
3
6
10
8
7
4
...

output:

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

result:

ok Correct (10000 test cases)

Test #3:

score: -100
Wrong Answer
time: 18ms
memory: 3776kb

input:

10000
3
1
2

output:

? 1 3
? 1 2
! -1

result:

wrong answer Wrong prediction (test case 1)