QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#542884 | #8939. Permutation | ucup-team1766# | RE | 0ms | 0kb | C++23 | 956b | 2024-09-01 06:54:13 | 2024-09-01 06:54:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const long double d = 1/2.62L;
int n;
int sum = 0;
void query(int l, int r) {
assert(1 <= l and l <= r);
sum += r - l + 1;
assert(sum <= 3*n);
cout << "? " << l << " " << r << endl;
}
void run() {
cin >> n;
int l = 1, r = n;
int mx = -1;
while (l+1 < r) {
if (mx == -1) {
query(l, r);
cin >> mx;
}
if (mx <= l + (r - l) / 2) {
int m = r - int((r - l + 1) * d);
if (m == r) m--;
query(l, m);
int x; cin >> x;
if (x == mx) {
r = m;
} else {
l = m+1;
mx = -1;
}
} else {
int m = l + int((r - l + 1) * d);
if (m == l) m++;
query(m, r);
int x; cin >> x;
if (x == mx) {
l = m;
} else {
r = m-1;
mx = -1;
}
}
}
if (l+1 == r) {
if (mx == -1) {
query(l, r);
cin >> mx;
}
if (mx == l) l = r;
}
cout << "! " << l << endl;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t; cin >> t; while (t--) run();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 5 3 3 3 2 6
output:
? 1 5 ? 1 4 ? 2 4 ? 2 3 ! 4