QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#542890 | #8939. Permutation | ucup-team1766# | RE | 1ms | 3580kb | C++23 | 977b | 2024-09-01 06:58:45 | 2024-09-01 06:58:46 |
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 and r <= n);
sum += r - l + 1;
assert(sum <= 3*n);
cout << "? " << l << " " << r << endl;
}
void run() {
sum = 0;
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: 100
Accepted
time: 1ms
memory: 3580kb
input:
3 5 3 3 3 2 6 6 3 1 4 3 3 2
output:
? 1 5 ? 1 4 ? 2 4 ? 2 3 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 2 4 ? 2 3 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Runtime Error
input:
10000 10 2 2 2 2 3 10 10 10 10 7 10 5 5 5 4 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 ? 3 7 ? 3 6 ! 7 ? 1 10 ? 1 7 ? 1 5 ? 2 5 ? 3 5