QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#681240 | #8939. Permutation | Rico64 | WA | 114ms | 3708kb | C++23 | 1.5kb | 2024-10-27 03:19:28 | 2024-10-27 03:19:33 |
Judging History
answer
#include <iostream>
using namespace std;
int query(int l, int r) {
if (r - l <= 1) return -2;
cout << "? " << l + 1 << ' ' << r << endl;
cout.flush();
int re;
cin >> re;
return re - 1;
}
void submit(int i) {
cout << "! " << i + 1 << endl;
cout.flush();
}
void solve() {
int n;
cin >> n;
int l = 0, r = n, n1 = -1;
while (l < r) {
if (n1 < 0) {
n1 = query(l, r);
}
int m = (r + l) / 2;
int ml = (m + l) / 2;
int mr = (r + m) / 2;
if (n1 >= m) {
int q2 = query(m, r);
if (q2 == n1) {
l = m;
} else {
int q3 = ml == l ? n1 : query(ml, r);
if (q3 == n1) {
l = ml;
r = m;
n1 = -1;
} else {
r = ml;
n1 = -1;
}
}
} else {
int q2 = query(l, m);
if (q2 == n1) {
r = m;
} else {
int q3 = mr == r ? n1 : query(l, mr);
if (q3 == n1) {
l = m;
r = mr;
n1 = -1;
} else {
l = mr;
n1 = -1;
}
}
}
}
submit(l);
}
int 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: 1ms
memory: 3564kb
input:
3 5 3 3 3 6 6 5 6 3 4 3 3
output:
? 1 5 ? 3 5 ? 3 4 ! 4 ? 1 6 ? 4 6 ? 2 6 ? 2 3 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 72ms
memory: 3708kb
input:
10000 10 2 2 1 3 5 10 10 10 8 7 10 5 1 5 6 10 4 4 4 5 10 10 6 3 2 10 3 3 5 2 10 1 5 5 9 10 10 1 3 1 6 10 2 4 4 9 9 10 3 3 3 3 10 4 1 7 8 9 10 8 7 8 4 5 10 4 1 1 9 9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? 10 11 ? 9 11 ! 9 ? 1 14 ? 1 7 ? 1 3 ? 1 5 ? 4 5 ! 4 ? 1 16 ? 1 8 ? 1 4 ? 1 6 ?...
result:
ok Correct (10000 test cases)
Test #4:
score: 0
Accepted
time: 114ms
memory: 3640kb
input:
10000 47 23 23 19 11 2 1 1 5 14 8 8 8 9 25 6 12 6 13 13 13 7 4 4 4 9 2 2 2 27 27 27 27 24 27 23 21 7 7 6 7 5 5 43 41 37 21 7 8 8 1 22 6 4 14 20 20 21 34 29 25 29 17 17 17 16 42 20 20 20 20 19 20 17 47 21 21 21 21 22 19 41 25 25 30 30 36 36 36 19 17 17 16 16 10 21 14 14 14 15 14 27 2 1 2 17 17 18 19 ...
output:
? 1 47 ? 1 23 ? 12 23 ? 6 23 ? 1 5 ? 1 2 ? 1 3 ? 4 5 ! 4 ? 1 14 ? 8 14 ? 8 10 ? 8 9 ! 10 ? 1 25 ? 1 12 ? 1 18 ? 13 18 ? 13 15 ? 13 14 ! 14 ? 1 7 ? 4 7 ? 4 5 ! 5 ? 1 9 ? 1 4 ? 1 2 ! 1 ? 1 27 ? 14 27 ? 21 27 ? 24 27 ? 22 27 ? 22 23 ! 22 ? 1 21 ? 1 10 ? 6 10 ? 3 10 ? 3 5 ? 4 5 ! 4 ? 1 43 ? 22 43 ? 11 4...
result:
ok Correct (10000 test cases)
Test #5:
score: -100
Wrong Answer
time: 8ms
memory: 3612kb
input:
10000 100 47 5 47 61 53 68 71 71 71 9 2 2 1 2 53 46 35 14 6 6 6 6 33 3 16 16 31 31 31 32 82 60 42 60 29 29 28 29 23 24 88 39 8 39 59 59 59 59 60 71 24 29 29 59 59 59 58 60 61 92 52 52 56 70 88 88 89 88 24 11 11 9 11 5 6 66 51 51 66 45 39 39 38 40 92 43 43 38 43 20 20 20 19 48 1 1 1 5 1 9 9 85 28 28 ...
output:
? 1 100 ? 1 50 ? 1 75 ? 51 75 ? 51 62 ? 51 68 ? 69 75 ? 69 71 ? 70 71 ! 70 ? 1 9 ? 1 4 ? 1 2 ? 1 3 ! 3 ? 1 53 ? 27 53 ? 14 53 ? 1 13 ? 1 6 ? 4 6 ? 5 6 ! 5 ? 1 33 ? 1 16 ? 1 24 ? 25 33 ? 29 33 ? 31 33 ? 31 32 ! 33 ? 1 82 ? 42 82 ? 21 82 ? 21 41 ? 21 30 ? 26 30 ? 23 30 ? 23 25 ? 23 24 ! 25 ? 1 88 ? 1 ...
result:
wrong answer Too long queries, n = 59, now length 178 (test case 445)