QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#607244 | #8939. Permutation | UESTC_OldEastWest# | WA | 81ms | 3680kb | C++17 | 1.0kb | 2024-10-03 14:27:51 | 2024-10-03 14:27:51 |
Judging History
answer
#include <bits/stdc++.h>
void charming() {
int n; std::cin >> n;
std::function<int(int, int)> Send = [&](int l, int r) {
if (l == r) return -1;
std::cout << "? " << l << ' ' << r << '\n';
std::cout.flush();
int rcv; std::cin >> rcv;
return rcv;
};
std::function<void(int)> Answer = [&](int x) {
std::cout << "! " << x << '\n';
std::cout.flush();
};
int l = 1, r = n, p = -1;
while (l < r) {
if (p == -1) p = Send(l, r);
if (l + 1 == r) {
if (p == l) ++l;
break;
}
int mid0 = l + (r - l + 2) / 3, mid1 = r - (r - l + 2) / 3;
if (p < mid1) {
int q = Send(l, mid1 - 1);
if (q == p) r = mid1 - 1;
else l = mid1, p = -1;
}
else {
int q = Send(mid0, r);
if (q == p) l = mid0;
else r = mid0 - 1, p = -1;
}
}
Answer(l);
}
signed main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
int t; std::cin >> t;
while (t--) charming();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3544kb
input:
3 5 3 3 5 6 6 3 1 4 3 3 3
output:
? 1 5 ? 3 5 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 2 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 81ms
memory: 3580kb
input:
10000 10 2 2 3 5 6 10 10 10 10 8 7 10 5 1 10 9 10 4 4 4 4 10 10 6 3 2 10 3 3 3 2 10 1 5 9 9 10 10 1 3 8 8 10 2 4 9 9 9 10 3 3 1 5 6 10 4 1 7 8 9 10 8 7 1 2 10 4 1 9 9 9 10 7 7 7 7 6 10 5 1 7 8 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