QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#553742 | #8939. Permutation | ucup-team191# | WA | 41ms | 1592kb | C++23 | 1013b | 2024-09-08 19:16:57 | 2024-09-08 19:16:58 |
Judging History
answer
#include <cstdio>
int ask(int l, int r) {
printf("? %d %d\n", l, r);
fflush(stdout);
int x; scanf("%d", &x);
return x;
}
int solve(int l, int r, int x = -1) {
if(x == -1 && l != r) x = ask(l, r);
if(l == r) return l;
if(l == r - 1) return l + r - x;
if(l == r - 2) {
int x = ask(l, r);
if(x == l) return solve(l + 1, r);
if(x == r) return solve(l, r - 1);
return (ask(l, x) == x) ? l : r;
}
int mid = (l + r) / 2;
if(x <= mid) {
int x_l = ask(l, mid);
if(x_l == x) return solve(l, mid, x);
int mid2 = (r + mid + 1) / 2;
if(ask(x, mid2) == x) return solve(mid + 1, mid2);
else return solve(mid2 + 1, r);
} else {
int x_r = ask(mid + 1, r);
if(x_r == x) return solve(mid + 1, r, x);
int mid2 = (l + mid) / 2;
if(ask(mid2 + 1, x) == x) return solve(mid2 + 1, mid);
else return solve(l, mid2);
}
}
int main() {
int T; scanf("%d", &T);
for(;T--;) {
int n; scanf("%d", &n);
printf("! %d\n", solve(1, n));
fflush(stdout);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 1592kb
input:
3 5 3 2 3 6 6 5 3 1 4 3 3
output:
? 1 5 ? 1 3 ? 3 4 ! 4 ? 1 6 ? 4 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 41ms
memory: 1536kb
input:
10000 10 2 2 3 2 10 10 10 9 8 7 10 5 1 5 6 6
output:
? 1 10 ? 1 5 ? 1 3 ? 2 4 ! 4 ? 1 10 ? 6 10 ? 9 10 ? 8 10 ? 6 7 ! 6 ? 1 10 ? 1 5 ? 5 8 ? 6 8 ? 6 8 ? 7 8
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 3)