QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#605477 | #8939. Permutation | ericmegalovania | WA | 21ms | 11612kb | C++20 | 2.4kb | 2024-10-02 17:25:34 | 2024-10-02 17:25:36 |
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[1]=0,dp[2]=1;
for(int i=3;i<N;i++){
int j=i*p,res=1e9,shit=-1;
for(int k=-5;k<5;k++) if(j-k>0 && i-(j-k)>0 && 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
*/
詳細信息
Test #1:
score: 100
Accepted
time: 13ms
memory: 11492kb
input:
3 5 3 3 2 6 6 6 3 4 3 2
output:
? 1 5 ? 1 4 ? 1 3 ! 4 ? 1 6 ? 2 6 ? 3 6 ! 2 ? 1 4 ? 1 3 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 21ms
memory: 11612kb
input:
10000 10 2 2 2
output:
? 1 10 ? 1 9 ? 1 8 ? 1 7
result:
wrong answer Too long queries, n = 10, now length 34 (test case 1)