QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#607550 | #8939. Permutation | UESTC_NLNS | TL | 1ms | 3892kb | C++14 | 919b | 2024-10-03 15:17:32 | 2024-10-03 15:17:32 |
Judging History
answer
#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
map<pii,int> mp;
const int N=1e6+5;
void answer(int x)
{
printf("! %d\n",x);
fflush(stdout);
return;
}
int query(int l,int r)
{
if(mp.find({l,r})!=mp.end()) return mp[{l,r}];
int x;
printf("? %d %d\n",l,r);
fflush(stdout);
scanf("%d",&x);
mp[{l,r}]=x;
return x;
}
void solve(int l,int r)
{
if(l==r)
{
answer(l);
return;
}
int mid=(l+r)/2,lmid,x=query(l,r),y;
if(l+1==r)
{
if(x==l) answer(r);
else answer(l);
return;
}
int len=max(2,(int)((r-l)*0.618+l));
if(x<=mid)
{
y=query(l,l+len-1);
if(x==y) solve(l,l+len-1);
else solve(l+len,r);
}
else
{
y=query(r-len+1,r);
if(x==y) solve(r-len+1,r);
else solve(l,r-len);
}
return;
}
int T,n;
int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
solve(1,n);
mp.clear();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3892kb
input:
3 5 3 2 5 6 6 3 1 4 3 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 3 6 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Time Limit Exceeded
input:
10000 10 2 2 2 1 3 10 10 10 10
output:
? 1 10 ? 1 6 ? 1 4 ? 1 2 ? 3 4 ! 4 ? 1 10 ? 5 10 ? 3 10 ? 4 10