QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#605450 | #8939. Permutation | ericmegalovania | WA | 1ms | 3716kb | C++20 | 2.0kb | 2024-10-02 17:17:27 | 2024-10-02 17:17:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
//#define ONLINE
#ifndef ONLINE
char DEBUG_BUFFER[1000];
#define debug(...) {sprintf(DEBUG_BUFFER,##__VA_ARGS__);\
cerr<<"\033[1;36m"<<DEBUG_BUFFER<<"\033[0;2m"<<"\033[0m";}
#else
#define debug(...) ;
#endif
using LL=long long;
using PII=pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define FAST_IO {ios::sync_with_stdio(false);cin.tie(nullptr);}
inline int read(){static int x; cin>>x; return x;}
inline LL readLL(){static LL x; cin>>x; return x;}
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
using LD=long double;
LD p=0.61803398875;
int cnt,len,mx_cnt,mx_len;
int ask(int l,int r){
// assert(l<r);
// assert(++cnt<=mx_cnt);
// assert((len+=r-l+1)<=mx_len);
cout<<"? "<<l<<" "<<r<<endl;
return read();
}
int calc(int l,int r,int pos){
if(l==r) return l;
if(l+1==r){
return pos==l?r:l;
}
if(l+2==r){
if(pos==l) return calc(l+1,r,ask(l+1,r));
if(pos==r) return calc(l,r-1,ask(l,r-1));
if(ask(l,pos)==pos) return l;
else return r;
}
if(l+3==r){
if(pos!=r){
if(ask(l,r-1)==pos) return calc(l,r-1,pos);
else return r;
}
else{
if(ask(l+1,r)==pos) return calc(l+1,r,pos);
else return l;
}
}
int len=r-l+1;
if(pos-l<=r-pos){
int mid=l+p*len-1;
if(ask(l,mid)==pos) return calc(l,mid,pos);
if(mid+1==r) return r;
return calc(mid+1,r,ask(mid+1,r));
}
else{
int mid=r-p*len+1;
if(ask(mid,r)==pos) return calc(mid,r,pos);
if(l==mid-1) return l;
return calc(l,mid-1,ask(l,mid-1));
}
}
void solve(){
int n=read();
mx_cnt=ceil((LD)1.5*log2(n)),mx_len=n*3;
cnt=len=0;
int ans=calc(1,n,ask(1,n));
cout<<"! "<<ans<<endl;
}
int main(){
int T=1;
cin>>T; //remember this !!!!!!
while(T--) solve();
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3716kb
input:
3 5 3 2 5 6 6 3 1 4 3 2
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 1 3 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3596kb
input:
10000 10 2 2 3 5 5 10 10 10 10 7 10 5 1 10 9 10 4 4 4 4 4 10 10 6 3 2 10 3 3 3 2 10 1 5 9 9 7 10 1 3 8 8 8 10 2 4 9 8 10 3 3 1 5 5 10 4 1 7 8 10 8 7 1 2 10 4 1 9 8 10 7 7 7 7 6 10 5 1 7 7 8 10 8 8 8 6 9 10 2 2 1 5 4 10 6 6 4 10 8 10 1 3 8 8 8 10 7 9 1 2 10 7 4 1 2 10 3 4 7 7 8 10 4 4 4 4 3 10 8 7 2 ...
output:
? 1 10 ? 1 6 ? 1 3 ? 4 6 ? 4 5 ! 4 ? 1 10 ? 4 10 ? 6 10 ? 7 10 ! 6 ? 1 10 ? 1 6 ? 7 10 ? 8 10 ! 7 ? 1 10 ? 1 6 ? 3 6 ? 3 5 ? 3 4 ! 3 ? 1 10 ? 4 10 ? 1 3 ? 1 2 ! 1 ? 1 10 ? 1 6 ? 1 3 ? 1 2 ! 1 ? 1 10 ? 1 6 ? 7 10 ? 7 9 ? 7 8 ! 8 ? 1 10 ? 1 6 ? 7 10 ? 7 9 ? 7 8 ! 7 ? 1 10 ? 1 6 ? 7 10 ? 7 9 ! 10 ? 1 1...
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 50)