QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#696433#8939. Permutation2018haha#RE 1ms3696kbC++171.3kb2024-10-31 22:34:422024-10-31 22:34:43

Judging History

This is the latest submission verdict.

  • [2024-10-31 22:34:43]
  • Judged
  • Verdict: RE
  • Time: 1ms
  • Memory: 3696kb
  • [2024-10-31 22:34:42]
  • Submitted

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<=2*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: 3696kb

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

result: