QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#696463 | #8939. Permutation | 2018haha# | WA | 4ms | 3612kb | C++17 | 1.4kb | 2024-10-31 22:43:59 | 2024-10-31 22:44:01 |
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;
}
int mid=(l+r)/2;
int ans=Query(l,r);
if(ans<=mid)
{
int ansl=Query(l,mid);
if(ansl==ans) return Calc(l,mid);
else return Calc(mid+1,r);
}
else
{
int ansr=Query(mid+1,r);
if(ansr==ans) return Calc(mid+1,r);
else return Calc(l,mid);
}
// 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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3612kb
input:
3 5 3 2 5 6 6 5 3 1 4 3 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 1 2 ! 2 ? 1 4 ? 3 4 ! 4
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 4ms
memory: 3544kb
input:
10000 10 2 2 3 5 10 10 10 9 7 7 10 5 1 10 9 6
output:
? 1 10 ? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 10 ? 6 10 ? 9 10 ? 6 8 ? 6 7 ! 6 ? 1 10 ? 1 5 ? 6 10 ? 9 10 ? 6 8 ? 6 7
result:
wrong answer Too many queries , n = 10 , now_q 6 (test case 3)