QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#642826#8939. PermutationWolam#WA 7ms3656kbC++201.4kb2024-10-15 16:27:372024-10-15 16:27:38

Judging History

This is the latest submission verdict.

  • [2024-10-15 16:27:38]
  • Judged
  • Verdict: WA
  • Time: 7ms
  • Memory: 3656kb
  • [2024-10-15 16:27:37]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
map<pair<int,int>,int> mp;
int ask(int l,int r)
{
    if(mp[{l,r}])
    {
        return mp[{l,r}];
    }
    cout<<"? "<<l<<" "<<r<<endl;
    int pos;
    cin>>pos;
    return mp[{l,r}]=pos;
}
int query(int l,int r)
{
    if(l==r)
    {
        return l;
    }
    else if(r-l+1==2)
    {
        int p=ask(l,r);
        if(p==l)
        {
            return r;
        }
        else
        {
            return l;
        }
    }
    else
    {
        int p=ask(l,r);
        int mid=(l+(r-l+1)/3);
        if(p>=mid&&p<=r)//[l,mid-1] [mid,r]
        {
            if(ask(mid,r)==p)
            {
                return query(mid,r);
            }
            else
            {
                return query(l,mid-1);
            }
        }
        else//[l,mid] [mid+1,r]
        {
            mid=(r-(r-l+1)/3);
            if(ask(l,mid)==p)
            {
                return query(l,mid);
            }
            else
            {
                return query(mid+1,r);
            }
        }
    }
}
void solve(void)
{
    mp.clear();
    int n;
    cin>>n;
    int ans=query(1,n);
    cout<<"! "<<ans<<endl;
}
int main(void)
{
    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: 0ms
memory: 3656kb

input:

3
5
3
3
3
3
6
6
3
1
4
3
3
3

output:

? 1 5
? 2 5
? 3 5
? 3 4
! 4
? 1 6
? 3 6
? 1 2
! 2
? 1 4
? 2 4
? 3 4
! 4

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 7ms
memory: 3580kb

input:

10000
10
2
2
2
2
2

output:

? 1 10
? 1 7
? 1 5
? 2 5
? 2 4
? 2 3

result:

wrong answer Too many queries , n = 10 , now_q 6 (test case 1)