QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#619899 | #8939. Permutation | zzpcd# | WA | 3ms | 3652kb | C++20 | 1.1kb | 2024-10-07 15:50:28 | 2024-10-07 15:50:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
const double k = 0.629;
int ask(int l, int r) {
if(l == r) return -1;
cout << "? " << l << ' ' << r << endl;
int x;
cin >> x;
return x;
}
void answer(int x) {
cout << "! " << x << endl;
return;
}
void solve(int l, int r, int sec = -1) {
if(l == r) {
answer(l);
return;
}
if(sec == -1) sec = ask(l, r);
if(l + 1 == r) {
answer(l == sec ? r : l);
return;
}
int mid = (r - l + 1) * k;
if(l + mid - 1 == k) {
mid = l + mid - 1;
int u = ask(l, mid);
if(u == sec) {
return solve(l, mid, sec);
} else return solve(mid + 1, r, -1);
} else {
mid = r - mid + 1;
int u = ask(mid, r);
if(u == sec) {
return solve(mid, r, sec);
} else return solve(l, mid - 1, -1);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while(T--) {
int n;
cin >> n;
solve(1, n);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
input:
3 5 3 3 3 6 6 5 3 1 4 3 3
output:
? 1 5 ? 3 5 ? 3 4 ! 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: 3ms
memory: 3556kb
input:
10000 10 2 9 2 3 1
output:
? 1 10 ? 5 10 ? 1 4 ? 3 4 ? 1 2 ! 2
result:
wrong answer Wrong prediction (test case 1)