QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#653091 | #8939. Permutation | Yoshinow2001 | RE | 1ms | 3712kb | C++20 | 1.5kb | 2024-10-18 19:33:02 | 2024-10-18 19:33:07 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define int long long
int cnt = 0;
int len = 0;
int C = 0;
int L = 0;
int ask(int l , int r){
if(l == r) return -1;
cnt++;
len += r - l + 1;
assert(cnt <= C);
assert(len <= L);
cout <<"? " <<l <<' '<<r <<endl;
int ret;
cin >> ret;
return ret;
}
void answer(int x){
cout <<"! " << x <<endl;
}
void f(int l , int r);
void g(int l ,int r ,int x);
const double a=pow(2,2.0/3.0);
const double dx = 0.618;
void solve() {
int n;
cin >> n;
L = 3 * n;
C = ceil(1.5 * log2(n));
cnt = len = 0;
f(1 , n);
}
int32_t main(){
fastio;
int tc;cin>>tc;
while(tc--)solve();
return 0;
}
void f(int l,int r){
assert(l <= r);
if(l >= r){
answer(l);
return;
}
int s = ask(l , r);
g( l , r, s);
}
void g(int l , int r , int x){
int len = ceil((r - l + 1) * dx - 1);
assert(l != r);
if(r - l + 1 <= 2){
answer(l ^ r ^ x);
return;
}
if(l + len >= x){
int R = l + len;
int s = ask(l , R);
if(s != x) f(R + 1, r);
else g(l , R , x);
}
else{
int L = r - len;
int s = ask(L , r);
if(s != x) f(l, L - 1);
else g(L, r , x);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
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
Runtime Error
input:
10000 10 2 2 2 2 3 10 10 10 10 7 10 5 5 1 6 10 4 4 4 4 4
output:
? 1 10 ? 1 7 ? 1 5 ? 1 4 ? 1 3 ! 4 ? 1 10 ? 4 10 ? 6 10 ? 7 10 ! 6 ? 1 10 ? 1 7 ? 1 5 ? 6 7 ! 7 ? 1 10 ? 1 7 ? 1 5 ? 1 4 ? 2 4