QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#607468 | #8939. Permutation | UESTC_DECAYALI# | RE | 0ms | 0kb | C++20 | 1.8kb | 2024-10-03 14:59:34 | 2024-10-03 14:59:39 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<cmath>
#include<map>
#include<cassert>
#define RI register int
#define CI const int&
using namespace std;
const int N=1000000;
const double alpha=pow(2.0,2.0/3.0);
const double theta=alpha/(1.0+alpha);
int t,n,cnt,sum,f[N+5],pos[N+5]; map <pair <int,int>,int> rst;
inline int ask(CI l,CI r)
{
assert(1<=l&&r<=n);
assert(l<=r);
assert(r-l+1>=2);
if (rst.count({l,r})) return rst[{l,r}];
printf("? %d %d\n",l,r); fflush(stdout);
++cnt; sum+=r-l+1;
int res; scanf("%d",&res); return rst[{l,r}]=res;
}
inline void answer(CI p)
{
printf("! %d\n",p); fflush(stdout);
}
int main()
{
f[1]=0; f[2]=1;
for (RI i=3;i<=N;++i)
{
int st=max(1,(int)(theta*i)-1);
pos[i]=st; f[i]=max(f[st],f[i-st]+1)+1;
for (RI j=1;j<=3;++j)
{
int y=min(st+j,i-1);
int tmp=max(f[y],f[i-y]+1)+1;
if (tmp<f[i]) f[i]=tmp,pos[i]=y;
}
}
//for (RI i=1;i<=N;++i) assert(f[i]<=(int)ceil(1.5L*log2(i)));
for (scanf("%d",&t);t;--t)
{
scanf("%d",&n); rst.clear(); cnt=0; sum=0;
int l=1,r=n;
while (r-l+1>2)
{
int smx=ask(l,r),len=pos[r-l+1];
if (smx<=l+len-1)
{
int tmp=ask(l,l+len-1);
if (smx==tmp) r=l+len-1; else l=l+len-1;
} else
{
int tmp=ask(r-len+1,r);
if (smx==tmp) l=r-len+1; else r=r-len+1;
}
}
assert(l<=r);
if (l==r) answer(l); else
{
int tmp=ask(l,r);
if (tmp==l) answer(r); else answer(l);
}
assert(cnt<=(int)ceil(1.5L*log2(n)));
assert(sum<=3*n);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 5 3 2 3 3 6 6 5 3 4
output:
? 1 5 ? 1 3 ? 3 5 ? 3 4 ! 4 ? 1 6 ? 4 6 ? 1 4 ? 3 4 ? 1 3