QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#885615 | #9734. Identify Chord | Air_Color5 | WA | 1ms | 3840kb | C++14 | 1.2kb | 2025-02-06 16:37:58 | 2025-02-06 16:38:06 |
Judging History
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);
}
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: 0
Wrong Answer
time: 1ms
memory: 3840kb
input:
2 6 2 2 2 1 1 2 -1
output:
? 1 4 ? 1 4 ? 6 4 ? 3 4 ? 2 4 ? 1 3 ! 1 5
result:
wrong answer Wrong answer n=6, actual=2-4, guessed=1-5 (test case 1)