QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#557935 | #8939. Permutation | aaaaa | WA | 5ms | 3668kb | C++23 | 1.8kb | 2024-09-11 12:27:45 | 2024-09-11 12:27:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T;
ll N;
ll ret;
ll l, r;
ll current, st;
ll query(ll x, ll y) {
cout << "? " << x << " " << y << endl;
cin >> ret;
return ret;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> T;
while (T--) {
cin >> N;
if (N == 1) {
cout << "! " << 1 << endl;
continue;
}
l = 1;
r = N;
st = query(1, N);
while (r-l > 2) {
current = l+ll((r-l+1)*0.618)-1;
if (st < current) {
if (query(l, current) == st) {
r = current;
}
else {
st = query(current+1, r);
l = current+1;
}
}
else {
current = r-ll((r-l+1)*0.618);
if (query(current+1, r) == st) {
l = current+1;
}
else {
st = query(l, current);
r = current;
}
}
}
if (l == r-1) {
if (st == l) {
l = r;
}
}
else {
if (st <= l+1) {
if (query(l, l+1) == st) {
if (st == l) {
++l;
}
}
else {
l = r;
}
}
else {
if (query(l, l+1) == l) {
++l;
}
}
}
cout << "! " << l << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3668kb
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: 5ms
memory: 3612kb
input:
10000 10 2 2 3 5 5 10 10 10 8 5 5 10 5 1 10 9 8 10 4 4 6 2 1 10 10 6 3 4 2 10 3 3 6 3 2 10 1 5 9 10 7 10 1 3 8 9 8 10 2 4 9 9 10 3 3 5 1 2
output:
? 1 10 ? 1 6 ? 1 3 ? 4 6 ? 4 5 ! 4 ? 1 10 ? 5 10 ? 8 10 ? 5 7 ? 5 6 ! 6 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ? 7 8 ! 7 ? 1 10 ? 1 6 ? 4 6 ? 1 3 ? 1 2 ! 3 ? 1 10 ? 5 10 ? 1 4 ? 3 4 ? 1 2 ! 1 ? 1 10 ? 1 6 ? 4 6 ? 1 3 ? 1 2 ! 1 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ? 7 8 ! 8 ? 1 10 ? 1 6 ? 7 10 ? 9 10 ? 7 8 ! 7 ? 1 10 ? 1 ...
result:
wrong answer Wrong prediction (test case 10)