QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#605485 | #8939. Permutation | ericmegalovania | WA | 17ms | 11508kb | C++20 | 2.4kb | 2024-10-02 17:26:57 | 2024-10-02 17:27:06 |
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;
#define N 1000001
int dp[N],fuck[N];
void init(){
dp[2]=1,dp[3]=2;
for(int i=4;i<N;i++){
int j=i*p,res=1e9,shit=-1;
for(int k=-5;k<5;k++) if(j-k>1 && i-(j-k)>1 && j-k<N && i-(j-k)<N){
if(dp[j-k]+dp[i-(j-k)]<res){
res=dp[j-k]+dp[i-(j-k)];
shit=j-k;
}
}
dp[i]=res,fuck[i]=shit;
}
}
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;
int mid=l+fuck[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;
int mid=r-fuck[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(){
init();
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 12ms
memory: 11392kb
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: 17ms
memory: 11508kb
input:
10000 10 2 2 2 2
output:
? 1 10 ? 1 8 ? 1 6 ? 1 4 ? 1 3
result:
wrong answer Too long queries, n = 10, now length 31 (test case 1)