QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#858245#8939. Permutationbamboo123WA 129ms3584kbC++14897b2025-01-16 15:18:342025-01-16 15:18:35

Judging History

This is the latest submission verdict.

  • [2025-01-16 15:18:35]
  • Judged
  • Verdict: WA
  • Time: 129ms
  • Memory: 3584kb
  • [2025-01-16 15:18:34]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e6 + 5;
int query(int l, int r) {
	cout << "? " << l << " " << r << endl;
	int x; cin >> x;
	return x;
}
int getlen(int l, int r) {
	if(r - l > 10)
		return (r - l) * 2 / 3;
	else
		return (r - l) * 3 / 5;
}
void solve() {
	int n; cin >> n;
	int l = 1, r = n, lst = query(1, n);
	while(l + 1 < r) {
		if(lst <= (l + r) / 2) {
			int mid = l + getlen(l, r);
			if(lst == query(l, mid))
				r = mid;
			else {
				l = mid + 1;
				if(l != r)
					lst = query(l, r);
			}
		}
		else {
			int mid = r - getlen(l, r);
			if(lst == query(mid, r))
				l = mid;
			else {
				r = mid - 1;
				if(l != r)
					lst = query(l, r);
			}
		}
	}	
	cout << "! " << (l == r ? l : (l == lst ? r : l)) << endl;
}
signed main() {
	int T; cin >> T;
	while(T--)
		solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3456kb

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: 126ms
memory: 3456kb

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: 0
Accepted
time: 129ms
memory: 3584kb

input:

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

output:

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

result:

ok Correct (10000 test cases)

Test #4:

score: 0
Accepted
time: 101ms
memory: 3584kb

input:

10000
47
23
23
31
2
2
2
1
3
14
8
8
8
7
9
25
6
6
4
13
13
12
15
7
4
2
6
6
9
2
2
2
2
27
27
27
27
27
24
21
20
21
7
7
7
5
3
3
43
41
21
7
7
8
4
3
1
22
6
14
20
20
19
21
34
29
29
25
17
17
17
16
42
20
20
20
20
20
20
20
19
47
21
21
21
21
21
20
19
19
41
25
25
30
33
33
34
36
19
17
17
17
16
12
12
21
14
14
14
14
...

output:

? 1 47
? 1 31
? 11 31
? 1 10
? 1 6
? 1 4
? 1 2
? 3 4
! 4
? 1 14
? 6 14
? 6 10
? 6 8
? 9 10
! 10
? 1 25
? 1 17
? 1 11
? 12 17
? 12 15
? 12 13
? 14 15
! 14
? 1 7
? 1 4
? 5 7
? 5 6
! 5
? 1 9
? 1 5
? 1 3
? 1 2
! 1
? 1 27
? 10 27
? 16 27
? 20 27
? 23 27
? 20 22
? 20 21
! 22
? 1 21
? 1 14
? 1 9
? 5 9
? 1 ...

result:

ok Correct (10000 test cases)

Test #5:

score: -100
Wrong Answer
time: 12ms
memory: 3584kb

input:

10000
100
47
61
93
96
71
71
71
71
9
2
2
2
1
53
46
35
6
6
6
6
6
6
33
3
16
31
31
31
30
32
82
60
29
4
8
23
21
26
27
24
88
39
39
39
25
59
59
59
59
59
71
24
29
59
59
59
59
60
61
61
92
52
52
45
88
88
88
85
89
89
24
11
11
9
5
5
5
66
51
51
51
51
45
39
39
38
40
92
43
43
50
20
20
20
20
20
19
48
1
1
1
1
1
5
9
...

output:

? 1 100
? 1 67
? 68 100
? 79 100
? 68 78
? 68 74
? 68 71
? 70 71
! 70
? 1 9
? 1 5
? 1 3
? 1 2
! 3
? 1 53
? 19 53
? 1 18
? 1 12
? 1 8
? 4 8
? 4 6
? 5 6
! 5
? 1 33
? 1 22
? 23 33
? 27 33
? 30 33
? 30 31
? 32 33
! 33
? 1 82
? 28 82
? 1 27
? 1 18
? 19 27
? 19 23
? 24 27
? 26 27
? 24 25
! 25
? 1 88
? 1 5...

result:

wrong answer Too many queries , n = 94 , now_q 11 (test case 131)