QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#554441 | #8939. Permutation | andrewgopher | WA | 1ms | 3604kb | C++14 | 1.9kb | 2024-09-09 11:17:23 | 2024-09-09 11:17:24 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define int long long
int query(int l, int r){
cout << "? " << min(l,r) << " " << max(l,r) << endl;
int x;
cin>>x;
return x;
}
int quarter(int l, int r){
if (r-l+1==1){
return l;
}
int second = query(l,r);
int mid = (l+r+rand()%2)/2;
//ranges are [l,mid] and [mid+1,r]
bool isL;//is [l,mid] otherwise [mid+1,r]
if (second<=mid){
if (l==mid){
isL = false;
} else {
isL = query(l,mid)==second;
}
} else {
if (mid+1==r){
isL = true;
} else {
isL = query(mid+1,r)!=second;
}
}
int curL, curR;
if (isL){
curL = l;
curR = mid;
} else {
curL = mid+1;
curR = r;
}
if (curL==curR){
return curL;
}
int midQ = (curL+curR+rand()%2)/2;
//ranges are [curL,midQ] and [midQ+1,curR]
bool isLQ;
if (second < curL){
isLQ = query(second,midQ) == second;
} else if (second >= curL && second <= midQ){
if (curL==midQ){
isLQ = false;
} else{
isLQ = query(curL,midQ)==second;
}
} else if (second >= midQ+1 && second <= curR){
if (midQ+1==curR){
isLQ = true;
} else {
isLQ = query(midQ+1,curR) != second;
}
} else if (second>curR) {
isLQ = query(midQ+1,second)!=second;
} else {
assert(false);
}
if (isLQ) {
return quarter(curL,midQ);
} else {
return quarter(midQ+1,curR);
}
}
void solve() {
int n;
cin >> n;
int ans = quarter(1,n);
cout << "! " << ans << endl;
}
signed main() {
int t;
cin>>t;
while (t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3604kb
input:
3 5 3 2 3 6 6 5 5 3
output:
? 1 5 ? 1 3 ? 3 4 ! 4 ? 1 6 ? 5 6 ? 4 6 ? 1 3 ? 3 3
result:
wrong answer Too many queries , n = 6 , now_q 5 (test case 2)