QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#607108 | #8939. Permutation | UESTC_OldEastWest# | WA | 4ms | 3572kb | C++17 | 1019b | 2024-10-03 13:56:01 | 2024-10-03 13:56:03 |
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 mid = l + r >> 1;
if (p <= mid) {
int q = Send(l, mid);
if (q == p) r = mid;
else l = mid + 1, p = -1;
}
else {
int q = Send(mid + 1, r);
if (q == p) l = mid + 1;
else r = mid, 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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3556kb
input:
3 5 3 2 5 6 6 5 3 1 4 3 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 4ms
memory: 3572kb
input:
10000 10 2 2 3 5 10 10 10 9 7 7 10 5 1 10 9 6
output:
? 1 10 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 10 ? 6 10 ? 9 10 ? 6 8 ? 6 7 ! 6 ? 1 10 ? 1 5 ? 6 10 ? 9 10 ? 6 8 ? 6 7
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 3)