QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#667916#8939. Permutationzhenghanyun#WA 92ms3764kbC++14884b2024-10-23 09:44:342024-10-23 09:44:34

Judging History

This is the latest submission verdict.

  • [2024-10-23 09:44:34]
  • Judged
  • Verdict: WA
  • Time: 92ms
  • Memory: 3764kb
  • [2024-10-23 09:44:34]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 1e6 + 5;

mt19937_64 rng(chrono::steady_clock().now().time_since_epoch().count());

int T, n;

inline int ask(int l, int r) {
	cout << "? " << l << " " << r << endl;
	int res;
	cin >> res;
	return res;
}

inline void print(int pos) {
	cout << "! " << pos << endl;
}

inline int solve(int l, int r, int pos) {
	if (l == r) {
		return l;
	}
	if (!pos) {
		pos = ask(l, r);
	}
	if (l + 1 == r) {
		return (pos == l) ? r : l;
	}
	int mid = (l + r) >> 1;
	if (pos <= mid) {
		if (ask(l, mid) == pos) {
			return solve(l, mid, pos);
		}
		return solve(mid + 1, r, 0);
	}
	if (ask(mid, r) == pos) {
		return solve(mid, r, pos);
	}
	return solve(l, mid - 1, 0);
}

int main() {
	cin >> T;
	while (T--) {
		cin >> n;
		print(solve(1, n, 0));
	}
	return 0;
}

詳細信息

Test #1:

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

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: 92ms
memory: 3764kb

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: 11ms
memory: 3552kb

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)