QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#606654#8939. Permutationliguo#WA 80ms3956kbC++20828b2024-10-03 11:15:152024-10-03 11:15:16

Judging History

This is the latest submission verdict.

  • [2024-10-03 11:15:16]
  • Judged
  • Verdict: WA
  • Time: 80ms
  • Memory: 3956kb
  • [2024-10-03 11:15:15]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
void solve(){
	int n;scanf("%d",&n);
	int l=1,r=n,sl;
	printf("? %d %d\n",l,r);
	fflush(stdout);
	scanf("%d",&sl);
	int fl=0;
	while(l<r){
		if(fl==1){
			printf("? %d %d\n",l,r);
			fflush(stdout);
			scanf("%d",&sl);
			fl=0;
		}
		if(l+1==r){
			printf("! %d\n",l+r-sl);
			fflush(stdout);
			return;
		}
		int mid=l+(r-l)/2;
		if(l<=sl&&sl<=mid){
			printf("? %d %d\n",l,mid);
			fflush(stdout);
			int res;scanf("%d",&res);
			if(res==sl)
				r=mid;
			else
				l=mid+1,fl=1;
		}
		else{
			printf("? %d %d\n",mid,r);
			fflush(stdout);
			int res;scanf("%d",&res);
			if(res==sl)
				l=mid;
			else
				r=mid-1,fl=1;
		}
	}
	printf("! %d\n",l);
	fflush(stdout);
}
int main(){
	int t;scanf("%d",&t);
	while(t--){
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: 0
Accepted
time: 80ms
memory: 3896kb

input:

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

output:

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

result:

ok Correct (10000 test cases)

Test #3:

score: -100
Wrong Answer
time: 35ms
memory: 3956kb

input:

10000
3
1
2
11
5
5
5
5
4
2
2
19
3
3
4
6
8
9
7
5
7
1
2
3
3
3
19
6
6
10
1
2
4
2
2
15
11
11
11
11
10
14
1
1
1
2
3
16
4
4
1
8
8
7
3
3
2
19
13
17
5
5
5
4
2
2
4
1
2
3
7
2
2
2
3
2
2
17
1
1
1
2
4
14
9
9
9
9
8
20
9
3
18
17
13
13
13
6
4
4
3
5
18
7
7
7
5
9
8
8
8
6
5
8
6
6
6
5
16
10
10
10
10
10
6
1
3
6
5
10
3
3...

output:

? 1 3
? 1 2
! 3
? 1 11
? 1 6
? 3 6
? 4 6
? 4 5
! 6
? 1 2
! 1
? 1 19
? 1 10
? 1 5
? 6 10
? 6 8
? 9 10
! 10
? 1 7
? 4 7
? 1 3
? 1 2
! 3
? 1 3
? 2 3
! 2
? 1 19
? 1 10
? 5 10
? 1 4
? 1 2
? 3 4
! 3
? 1 2
! 1
? 1 15
? 8 15
? 8 11
? 9 11
? 10 11
! 9
? 1 14
? 1 7
? 1 4
? 1 2
? 3 4
! 4
? 1 16
? 1 8
? 1 4
? 5...

result:

wrong answer Too many queries , n = 16 , now_q 7 (test case 443)