QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#885621#9734. Identify ChordAir_Color5RE 1ms3840kbC++141.2kb2025-02-06 16:40:272025-02-06 16:40:29

Judging History

This is the latest submission verdict.

  • [2025-02-06 16:40:29]
  • Judged
  • Verdict: RE
  • Time: 1ms
  • Memory: 3840kb
  • [2025-02-06 16:40:27]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
int n;
int Query(int a, int b) {
	if (a == b) {
		return 0;
	}
	printf("? %d %d\n", a, b);
	fflush(stdout);
	int v;
	scanf("%d", &v);
	return v;
}
inline int Prev(int a) {
	return (a == 1 ? n : a - 1);
}
inline int Next(int a) {
	return (a == n ? 1 : a + 1);
}
inline int Walk(int a, long long b) {
	return (((long long)a + b) % n + n - 1) % n + 1;
}
random_device rd;
mt19937 mt(rd());
void Solve() {
	scanf("%d", &n);
	int a, b, DIS;
	a = 1, b = 1 + n / 2;
	if (Query(a, b) == n / 2 and n % 2 == 1) {
		b++;
	}
	if (Query(a, b) == n / 2) {
		a++;
		Walk(b, 1);
	}
	DIS = Query(a, b);
	assert(DIS != n / 2);
	int d;
	if (Query(Prev(a), b) == DIS - 1) {
		d = -1;
	}
	else {
		d = 1;
	}
	for (int i = __lg(n) - 1; i >= 0; i--) {
		int A = Walk(a, d * (1 << i));
		int D = Query(A, b);
		if ((1ll << i) + D == DIS) {
			DIS = D;
			a = A;
		}
	}
	if (Query(a, Walk(b, DIS - 1)) == 1) {
		b = Walk(b, DIS - 1);
	}
	else {
		b = Walk(b, 1 - DIS);
	}
	printf("! %d %d\n", a, b);
	fflush(stdout);
	int res;
	scanf("%d", &res);
	if (res == -1) {
		exit(0);
	}
}
signed main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		Solve();
	}
	return 0;
}

详细

Test #1:

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

input:

2
6
2
2
2
2
1
1
1
1
4
1
1
1
1
1
1
1

output:

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

result:

ok ok (2 test cases)

Test #2:

score: -100
Runtime Error

input:

1000
15
5
5
5
6
1
1
2
1
1
19
5
5
5
6
1
5
3
4
1
1
17
5
5
5
6
4
3
4
1
1
15
6
6
6
7
3
5
6
3
1
14
5
5
5
6
3
5
4
5
1
15
3
3
3
4
3
3
2
1
1
17
8
8
8

output:

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

result: