QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#696440 | #8939. Permutation | 2018haha# | RE | 1ms | 3732kb | C++17 | 1.3kb | 2024-10-31 22:36:29 | 2024-10-31 22:36:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int n;
int total,cnt;
map<pair<int,int>,int> mem;
int Query(int l,int r)
{
if(l==r) return -1;
if(mem[{l,r}]) return mem[{l,r}];
total+=r-l;
cnt++;
assert(total<=3*n);
assert(cnt<=1.5*log2(n)+1);
cout<<"? "<<l<<" "<<r<<endl;
int ans;
cin>>ans;
return mem[{l,r}]=ans;
}
int Calc(int l,int r)
{
if(r-l+1==2)
{
int tmp=Query(l,r);
if(tmp==l) return r;
else return l;
}
if(l==r)
{
return l;
set<int> s;
int tmp=Query(l,l+1);
s.insert(tmp);
tmp=Query(l+1,l+2);
s.insert(tmp);
tmp=Query(l,l+2);
s.insert(tmp);
for(int i=l;i<=r;i++)
if(!s.count(i)) return i;
}
int mid=(l+r)/2;
int ans=Query(l,r);
int ansl=Query(l,mid);
int ansr=Query(mid+1,r);
if(ansl==ans) return Calc(l,mid);
if(ansr==ans) return Calc(mid+1,r);
if(ans<=mid) return Calc(mid+1,r);
else return Calc(l,mid);
}
void Solve()
{
mem.clear();
total=cnt=0;
cin>>n;
int ans=Calc(1,n);
cout<<"! "<<ans<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--) Solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3732kb
input:
3 5 3 2 5 6 6 3 5 1 4 3 1 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 1 3 ? 4 6 ? 1 2 ! 2 ? 1 4 ? 1 2 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Runtime Error
input:
10000 10 2 2 9 3 5 10 10 5 10 7 9
output:
? 1 10 ? 1 5 ? 6 10 ? 1 3 ? 4 5 ! 4 ? 1 10 ? 1 5 ? 6 10 ? 6 8 ? 9 10