QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#613541 | #8939. Permutation | nekoyellow | WA | 81ms | 3692kb | C++20 | 1.4kb | 2024-10-05 14:11:29 | 2024-10-05 14:13:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int query(int l, int r) {
cout << "? " << l << ' ' << r << endl;
int res;
cin >> res;
return res;
}
void solve() {
int n;
cin >> n;
int l = 1, r = n;
int k = query(1, n);
while (r-l > 1) {
if (r-l == 2) {
int m = (l+r)/2;
if (k > m) {
if (k == query(m, r)) {
l = m;
} else {
r = m-1;
}
} else {
if (k == query(l, m)) {
r = m;
} else {
l = m+1;
}
}
break;
}
if (k < (l+r)/2) {
int m = l + (r-l)/3*2;
if (k == query(l, m)) r = m;
else {
l = m+1;
if (l != r) k = query(l, r);
}
} else {
int m = r - (r-l)/3*2;
if (k == query(m, r)) l = m;
else {
r = m-1;
if (l != r) k = query(l, r);
}
}
}
if (l == r) {
cout << "! " << l << endl;
} else {
cout << "! " << (l == k ? r : l) << endl;
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t;
cin >> t;
for (; t; t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3644kb
input:
3 5 3 3 3 6 6 5 3 3 4 3 3 2
output:
? 1 5 ? 3 5 ? 3 4 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 2 3 ! 2 ? 1 4 ? 2 4 ? 2 3 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 81ms
memory: 3616kb
input:
10000 10 2 2 2 3 5 10 10 10 10 8 7 10 5 5 5 4 8 10 4 4 4 4 4 10 10 6 3 2 10 3 3 3 5 2 10 1 5 9 9 10 1 1 3 6 10 2 4 9 8 10 3 3 3 3 3 10 4 7 8 9 10 8 7 1 2 10 4 1 9 8 10 7 7 8 4 10 5 5 7 10 10 8 8 8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