QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#548271 | #8939. Permutation | ucup-team004# | TL | 0ms | 3656kb | C++20 | 1.3kb | 2024-09-05 16:42:50 | 2024-09-05 16:42:50 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
const double phi = (std::sqrt(5) - 1) / 2;
int query(int l, int r) {
std::cout << "? " << l + 1 << " " << r << std::endl;
int p;
std::cin >> p;
return p - 1;
}
void solve() {
int n;
std::cin >> n;
int l = 0, r = n;
int x = -1;
while (r - l - (x != -1) > 1) {
if (x == -1) {
x = query(l, r);
} else {
int len = std::ceil((r - l) * phi);
if (x < l + len) {
if (query(l, l + len) == x) {
r = l + len;
} else {
l = l + len;
x = -1;
}
} else {
if (query(r - len, r) == x) {
l = r - len;
} else {
r = r - len;
x = -1;
}
}
}
}
int p;
if (r - l == 1) {
p = l;
} else {
p = l + l + 1 - x;
}
std::cout << "! " << p + 1 << std::endl;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3656kb
input:
3 5 3 3 2 6 6 3 1 4 3 2
output:
? 1 5 ? 1 4 ? 1 3 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 1 3 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Time Limit Exceeded
input:
10000 10 2 2 2 2 3 10 10 10 10 7 10 5 5 1 6 10 4 4 4 4 4
output:
? 1 10 ? 1 7 ? 1 5 ? 1 4 ? 1 3 ! 4 ? 1 10 ? 4 10 ? 6 10 ? 7 10 ! 6 ? 1 10 ? 1 7 ? 1 5 ? 6 7 ! 7 ? 1 10 ? 1 7 ? 1 5 ? 1 4 ? 2 4 ? 3 4