QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#871007 | #8939. Permutation | thangthang | TL | 0ms | 3584kb | C++20 | 1.3kb | 2025-01-25 19:04:45 | 2025-01-25 19:04:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int qry(int l, int r){
cout << "? " << l << ' ' << r << endl;
int ans; cin >> ans;
return ans;
}
double base = 0.75;
int solve(int l, int r, int op){
if (l == r) return l;
if (l + 1 == r) return l ^ r ^ qry(l, r);
if (op == -1){
int mid = qry(l, r);
if (mid == l) return solve(l + 1, r, 0);
if (mid == r) return solve(l, r - 1, 1);
if (mid - l < r - mid){
if (qry(l, mid) == mid) return solve(l, mid - 1, 1);
return solve(mid + 1, r, 0);
}
if (qry(mid, r) == mid) return solve(mid + 1, r, 0);
return solve(l, mid - 1, 1);
}
int len = double(r - l) * base;
if (op == 0){
int mid = l + len - 1;
if (qry(l - 1, mid) == l - 1) return solve(l, mid, 0);
return solve(mid + 1, r, -1);
}
int mid = r - len + 1;
if (qry(mid, r + 1) == r + 1) return solve(mid, r, 1);
return solve(l, mid - 1, -1);
}
void process(){
int n; cin >> n;
int ans = solve(1, n, -1);
cout << "! " << ans << endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t; cin >> t; while (t --)
process();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
3 5 3 3 5 6 6 3 1 4 3 3
output:
? 1 5 ? 3 5 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Time Limit Exceeded
input:
10000 10 2 1 2 2 3
output:
? 1 10 ? 1 2 ? 2 7 ? 2 5 ? 2 3 ? 4 5