QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#554079 | #8939. Permutation | Charizard2021 | ML | 1ms | 3632kb | C++14 | 1.5kb | 2024-09-09 05:02:43 | 2024-09-09 05:02:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
long double phi = (sqrt(5.0) - 1.0)/2.0;
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 val = (int)((long double)(high - low + 1) * (long double)phi + (long double)0.5);
int mid;
if(cur <= val + low){
mid = val + low;
}
else{
mid = high - val;
}
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(){
// cout << fixed << setprecision(9) << phi << "\n";
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: 100
Accepted
time: 1ms
memory: 3632kb
input:
3 5 3 3 2 6 6 3 1 4 3 2
output:
? 1 5 ? 1 4 ? 1 3 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 1 3 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Memory Limit Exceeded
input:
10000 10 2 2 2 2 3 10 10 10 7 5 10 5 5 1 6 10 4 4 4 4 4 10 10 6 3 3 3
output:
? 1 10 ? 1 7 ? 1 5 ? 1 4 ? 1 3 ! 4 ? 1 10 ? 5 10 ? 7 10 ? 5 6 ! 6 ? 1 10 ? 1 7 ? 1 5 ? 6 7 ! 7 ? 1 10 ? 1 7 ? 1 5 ? 1 4 ? 3 4 ! 3 ? 1 10 ? 5 10 ? 1 4 ? 1 3 ? 1 3 ? 1 3