QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#599367 | #8939. Permutation | zookeeper | TL | 0ms | 0kb | C++14 | 1.6kb | 2024-09-29 03:51:32 | 2024-09-29 03:51:33 |
Judging History
answer
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int solve() {
int N;
cin >> N;
int L = 1, R = N, S = -1;
while (true) {
if (L == R) return L;
if (S == -1) {
cout << "? " << L << ' ' << R << endl;
cin >> S;
continue;
}
if (L + 1 == R) {
return S == L ? R : L;
}
if (S - L < R - S) {
// query right
int mid = (S + R) / 2;
cout << "? " << S << ' ' << mid << endl;
int SS;
cin >> SS;
if (SS == S) {
L = S;
R = mid;
if (L + 1 == R) {
return R;
}
continue;
}
L = mid + 1;
S = -1;
continue;
} else {
// query left
int mid = (L + S) / 2;
cout << "? " << mid << ' ' << S << endl;
int SS;
cin >> SS;
if (SS == S) {
R = S;
L = mid;
if (L + 1 == R) {
return L;
}
continue;
}
R = mid - 1;
S = -1;
}
}
// int ans = query(1, N);
// cout << "! " << ans << endl;
}
int main() {
fastio;
int T;
cin >> T;
for (;T>0;T--) {
int s = solve();
cout << "! " << s << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3 5 3 2
output:
? 1 5 ? 2 3 ! 1