QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#666420 | #8939. Permutation | xh_team# | WA | 30ms | 3752kb | C++20 | 1.8kb | 2024-10-22 18:21:39 | 2024-10-22 18:21:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2014;
mt19937 rnd(time(0));
int a[] = {-1, 4, 7, 2, 6, 5, 1, 9};
int ask(int l, int r) {
cout << '?' << ' ' << l << ' ' << r << endl;
int x;
cin >> x;
return x;
// int fi = -1, se = -1;
// for (int i = l; i <= r; i++) {
// fi = max(fi, a[i]);
// }
// int x = -1;
// for (int i = l; i <= r; i++) {
// if (a[i] != fi && a[i] > se) {
// se = a[i];
// x = i;
// }
// }
// return x;
}
int n, p, ans;
void dfs(int l, int r) {
if (r - l == 1) {
ans = l + r - p;
return;
}
if (r - l == 2) {
if (p == l) {
int q = ask(l + 1, r);
ans = l + 1 + r - q;
} else if (p == r) {
int q = ask(l, l + 1);
ans = l + l + 1 - q;
} else {
int q = ask(l, l + 1);
if (p == q) {
ans = l;
} else {
ans = r;
}
}
return;
}
int len23 = (r - l + 1) / 3 * 2;
int mid = l + r >> 1;
if (p <= mid) {
int q = ask(l, l + len23 - 1);
if (p == q) {
dfs(l, l + len23 - 1);
} else {
p = ask(l + len23, r);
dfs(l + len23, r);
}
} else {
int q = ask(r - len23 + 1, r);
if (p == q) {
dfs(r - len23 + 1, r);
} else {
p = ask(l, r - len23);
dfs(l, r - len23);
}
}
}
void solve() {
cin >> n;
p = ask(1, n);
dfs(1, n);
cout << '!' << ' ' << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
int tt;
cin >> tt;
while (tt--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3752kb
input:
3 5 3 1 3 5 6 6 3 1 4 3 3
output:
? 1 5 ? 1 2 ? 3 5 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 30ms
memory: 3640kb
input:
10000 10 2 2 2 1 3 10 10 10 7 5 10 5 1 10 9 8 10 4 4 4 4 10 10 6 3 4 2 10 3 3 3 4 2 10 1 5 9 10 7 10 1 3 8 8 10 2 4 9 9 10 3 3 3 3 10 4 1 7 8 9 10 8 7 1 2 4 10 4 1 9 9 10 7 7 7 8 6 10 5 1 7 8 10 10 8 8 8 7 9 10 2 2 1 5 10 6 6 8 10 10 1 3 8 8 10 7 9 4 4 10 7 8 4 4 10 3 4 7 8 10 10 4 4 4 3 6 10 8 7 4 ...
output:
? 1 10 ? 1 6 ? 1 4 ? 1 2 ? 3 4 ! 4 ? 1 10 ? 5 10 ? 7 10 ? 5 6 ! 6 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ? 7 8 ! 7 ? 1 10 ? 1 6 ? 3 6 ? 3 4 ! 3 ? 1 10 ? 5 10 ? 1 4 ? 3 4 ? 1 2 ! 1 ? 1 10 ? 1 6 ? 1 4 ? 3 4 ? 1 2 ! 1 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ? 7 8 ! 8 ? 1 10 ? 1 6 ? 7 10 ? 7 8 ! 7 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ! 1...
result:
ok Correct (10000 test cases)
Test #3:
score: -100
Wrong Answer
time: 7ms
memory: 3704kb
input:
10000 3 1 2 11 5 5 5 5 2 2 19 3 3 4 12 11 9 7 5 7 1 2 3 3 1 19 6 6 6 7 1 2 4 2 2 15 11 11 15 8 8 14 1 1 1 2 3 16 4 4 4 4 3 5 3 3 2 19 13 17 5 6 2 1 2 2 4 1 2 3 7 2 2 2 3 2 2 17 1 1 1 2 6 14 9 9 9 9 20 9 9 9 9 10 11 6 4 4 3 5 18 7 7 7 7 7 8 8 6 3 3 8 6 7 1 2 3 16 10 10 10 10 10 6 1 1 2 3 10 3 3 4 6 2...
output:
? 1 3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