QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#858702 | #8939. Permutation | lichenyu_ac | WA | 1ms | 3584kb | C++14 | 767b | 2025-01-16 20:51:36 | 2025-01-16 20:51:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int ask(int l, int r) {
if (l == r) return 0;
cout << "?" << l << " " << r << endl;
int ret; cin >> ret;
return ret;
}
int n;
int solve(int l, int r, int t) {
if (l == r) return l;
if (r - l + 1 == 2) {
if (t == r) return l;
else return r;
}
int mid = l + (r - l) * 0.618;
if (t <= mid) {
if (ask(l, mid) == t) return solve(l, mid, t);
else return solve(mid + 1, r, ask(mid + 1, r));
} else {
mid = l + (r - l) * 0.382;
if (ask(mid + 1, r) == t) return solve(mid + 1, r, t);
else return solve(l, mid, ask(l, mid));
}
}
void solve() {
cin >> n;
cout << solve(1, n, ask(1, n)) << endl;
}
int main() {
int T; cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3584kb
input:
3 5
output:
?1 5
result:
wrong answer Token parameter [name=type] equals to "?1", doesn't correspond to pattern "?|!" (test case 1)