QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#858178 | #8939. Permutation | dark_moon | WA | 4ms | 3584kb | C++14 | 1.6kb | 2025-01-16 14:45:07 | 2025-01-16 14:45:16 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
// auto IOS = ios::sync_with_stdio(false);
// auto CIN = cin.tie(nullptr);
int t;
int query(int l, int r){
if(l == r){
return 0;
}
int x;
cout << "? " << l << " " << r << "\n";
cout.flush();
cin >> x;
return x;
}
signed main(){
cin >> t;
while(t --){
int n;
cin >> n;
int l = 1, r = n, p = -1;
auto get = [](int l, int r, double form){
// return l + r >> 1;
int mid = (l + r) * form;
mid = min(mid, r - 1);
mid = max(mid, l);
return mid;
};
while(l < r){
if(p == -1){
p = query(l, r);
}
else{
int mid = l + r >> 1;
if(p <= mid){
int vmid = get(l, r, 0.6);
if(query(l, vmid) == p){
r = vmid;
}
else{
l = vmid + 1;
p = -1;
}
}
else{
int vmid = get(l, r, 1 - 0.6);
if(query(vmid + 1, r) == p){
l = vmid + 1;
}
else{
r = vmid;
p = -1;
}
}
}
}
cout << "! " << l << "\n";
cout.flush();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
3 5 3 2 5 6 6 3 1 4 3 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 4ms
memory: 3584kb
input:
10000 10 2 2 2 3 10 10 10 7 5 10 5 1 10 9 10 4 4 4 4 4 10 10 6 3 4 2 10 3 3 3 4 2 10 1 5 9 9 9 10 1 3 8 8 8 10 2 4 9 9 8 10 3 3 3 3 10 4 1 7 8 10 8 7 1 1 2 10 4 1 9 9 8 10 7 7 7 7 8 10 5 1 7 7 8 10 8 8 8 9 10 2 2 1 5 10 6 6 6 8 10 1 3 8 8 8 10 7 9 4 4 10 7 8 4 4 10 3 4 7 7 8 10 4 4 4 4 3 10 8 7 4 3 ...
output:
? 1 10 ? 1 6 ? 1 4 ? 1 3 ! 4 ? 1 10 ? 5 10 ? 7 10 ? 5 6 ! 6 ? 1 10 ? 1 6 ? 7 10 ? 8 10 ! 7 ? 1 10 ? 1 6 ? 3 6 ? 3 5 ? 3 4 ! 3 ? 1 10 ? 5 10 ? 1 4 ? 3 4 ? 1 2 ! 1 ? 1 10 ? 1 6 ? 1 4 ? 3 4 ? 1 2 ! 1 ? 1 10 ? 1 6 ? 7 10 ? 8 10 ? 8 9 ! 8 ? 1 10 ? 1 6 ? 7 10 ? 7 9 ? 7 8 ! 7 ? 1 10 ? 1 6 ? 7 10 ? 8 10 ? 8...
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 42)