QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#607286 | #8939. Permutation | UESTC_DECAYALI# | WA | 60ms | 11784kb | C++20 | 1.6kb | 2024-10-03 14:35:41 | 2024-10-03 14:35:42 |
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,f[N+5],pos[N+5]; map <pair <int,int>,int> rst;
inline int ask(CI l,CI r)
{
if (rst.count({l,r})) return rst[{l,r}];
printf("? %d %d\n",l,r); fflush(stdout); ++cnt;
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;
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+=len;
} else
{
int tmp=ask(r-len+1,r);
if (smx==tmp) l=r-len+1; else r-=len;
}
}
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)));
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 11ms
memory: 11644kb
input:
3 5 3 2 5 6 6 5 3 3 4 3 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 2 3 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 60ms
memory: 11764kb
input:
10000 10 2 2 3 5 10 10 10 8 7 10 5 1 10 9 6 10 4 4 4 4 10 10 6 3 3 2 10 3 3 3 2 10 1 5 9 9 9 10 1 3 8 8 8 10 2 4 9 9 8 10 3 3 1 5 10 4 1 7 8 9 10 8 7 1 1 2 10 4 1 9 9 8 10 7 8 2 1 4 10 5 1 7 6 10 10 8 8 6 9 10 2 1 7 7 7 10 6 6 8 10 10 1 3 8 8 8 10 7 9 5 5 4 10 7 8 4 4 4 10 3 4 7 8 10 10 4 4 4 3 10 8...
output:
? 1 10 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 10 ? 6 10 ? 8 10 ? 6 7 ! 6 ? 1 10 ? 1 5 ? 6 10 ? 8 10 ? 6 7 ! 7 ? 1 10 ? 1 5 ? 3 5 ? 3 4 ! 3 ? 1 10 ? 6 10 ? 1 5 ? 1 3 ? 2 3 ! 1 ? 1 10 ? 1 5 ? 1 3 ? 2 3 ! 1 ? 1 10 ? 1 5 ? 6 10 ? 8 10 ? 8 9 ! 8 ? 1 10 ? 1 5 ? 6 10 ? 6 8 ? 7 8 ! 7 ? 1 10 ? 1 5 ? 6 10 ? 8 10 ? 8 9 ! 1...
result:
ok Correct (10000 test cases)
Test #3:
score: -100
Wrong Answer
time: 57ms
memory: 11784kb
input:
10000 3 1 2 11 5 5 5 4 2 2 19 3 3 4 11 11 11 7 5 7 1 2 3 3 3 19 6 6 6 5 1 2 2 2 15 11 11 11 12 8 14 1 1 1 2 3 16 4 4 1 8 7 3 3 2 19 13 17 5 5 5 4 2 2 4 1 2 3 7 2 2 2 3 2 2 17 1 1 2 8 9 6 14 9 9 9 8 11 20 9 9 9 6 11 10 6 4 4 5 18 7 7 7 7 6 8 8 8 6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