QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#554071 | #8939. Permutation | Charizard2021 | WA | 1ms | 3616kb | C++14 | 1.2kb | 2024-09-09 04:33:22 | 2024-09-09 04:33:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int solve(int low, int high, int cur){
if(low == high){
return low;
}
if(cur == INT_MIN){
cout << "? " << low << " " << high << "\n";
cout.flush();
cin >> cur;
}
if(low + 1 == high){
if(cur == low){
return high;
}
else{
return low;
}
}
int mid = (low + high)/2;
if(cur <= mid){
cout << "? " << low << " " << mid << "\n";
cout.flush();
int x;
cin >> x;
if(x == cur){
return solve(low, mid, x);
}
else{
return solve(mid + 1, high, INT_MIN);
}
}
else{
cout << "? " << mid + 1 << " " << high << "\n";
cout.flush();
int x;
cin >> x;
if(x == cur){
return solve(mid + 1, high, x);
}
else{
return solve(low, mid, INT_MIN);
}
}
}
int main(){
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int res = solve(1, n, INT_MIN);
cout << "! " << res << "\n";
cout.flush();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3616kb
input:
3 5 3 2 5 6 6 5 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 3 3
result:
wrong answer Integer 3 violates the range [4, 6] (test case 2)