QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#666345 | #8939. Permutation | xh_team# | WA | 7ms | 3852kb | C++20 | 1.5kb | 2024-10-22 17:56:29 | 2024-10-22 17:56:31 |
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 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 mid = l-1+ (int)(r - l + 1)*0.35;
if (l == mid) mid++;
if (mid + 1 == r) mid--;
if (p <= mid) {
int q = ask(l, mid);
if (p == q) {
dfs(l, mid);
} else {
p = ask(mid + 1, r);
dfs(mid + 1, r);
}
} else {
int q = ask(mid + 1, r);
if (p == q) {
dfs(mid + 1, r);
} else {
p = ask(l, mid);
dfs(l, mid);
}
}
}
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: 3852kb
input:
3 5 3 3 5 6 6 3 1 4 3 3
output:
? 1 5 ? 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: -100
Wrong Answer
time: 7ms
memory: 3784kb
input:
10000 10 2 3 7 9 5 10 10 10 10 8 7 10 5 5 4 10 9
output:
? 1 10 ? 1 3 ? 4 10 ? 6 10 ? 4 5 ! 4 ? 1 10 ? 4 10 ? 6 10 ? 8 10 ? 6 7 ! 6 ? 1 10 ? 4 10 ? 4 5 ? 6 10 ? 8 10 ? 6 7
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 3)