QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#652689 | #8939. Permutation | Yoshinow2001# | TL | 0ms | 3524kb | C++20 | 1.4kb | 2024-10-18 19:01:10 | 2024-10-18 19:01:11 |
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 ask(int l , int r){
if(l == r) return -1;
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 int N = 3;
const int M = 5;
void solve() {
int n;
cin >> n;
f(1 , n);
}
int32_t main(){
fastio;
int tc;cin>>tc;
while(tc--)solve();
return 0;
}
void f(int l,int r){
if(l == r){
answer(l);
return;
}
int s = ask(l , r);
int l1 = s - l;
int l2 = r - s;
if(l1 < l2) {
int x = ask(l , s);
if(x != s) g(s , r ,s);
else g(l , s , s);
}
else{
int x = ask(s , r);
if(x == s) g(s , r ,s);
else g(l , s , s);
}
}
void g(int l , int r , int x){
int len = (r - l + 1) * N / M;
if(r - l + 1 == 2){
answer(l ^ r ^ x);
return;
}
if(x == l){
int s1 = ask(x , x + len);
if(s1 == x) g(x , x + len ,x);
else f(x + len + 1, r);
}
else{
int s1 = ask(x - len , x);
if(s1 == x) g(x - len , x ,x);
else f(l, x - len - 1);
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3524kb
input:
3 5 3 3 3 6 6 3 1 4 3 3
output:
? 1 5 ? 3 5 ? 3 4 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Time Limit Exceeded
input:
10000 10 2 1 2 2 2
output:
? 1 10 ? 1 2 ? 2 7 ? 2 5 ? 2 4 ? 2 3