QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#858608#8939. PermutationMightZeroWA 1ms3584kbC++201.9kb2025-01-16 19:38:132025-01-16 19:38:21

Judging History

This is the latest submission verdict.

  • [2025-01-16 19:38:21]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3584kb
  • [2025-01-16 19:38:13]
  • Submitted

answer

#include<bits/stdc++.h>
#define loop(x,l,r) for(ll (x) = (l);(x)<=(r);++(x))
#define rloop(x,l,r) for(ll (x) = (r);(x)>=(l);--(x))
#define elif else if
using namespace std;
using ll = long long;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x*=10;x+=ch-'0';ch=getchar();}
    return x*f;
}
inline void write(ll x)
{
    if(x<0){putchar('-');x=-x;}
    if(x%10==x){putchar(x+'0');return;}
    write(x/10);putchar(x%10+'0');
}
ll n,pos;
const double t=0.618;
ll get(ll l,ll r)
{
    ll x;
    cout<<"? "<<l<<" "<<r<<endl;
    cin>>x;
    return x;
}
void solve(ll l,ll r)
{
    //cerr<<l<<" "<<r<<endl;
    if(l==r)
    {
        cout<<"! "<<l<<endl;
        return;
    }
    if(l==r-1)
    {
        if(pos==l)cout<<"! "<<r<<endl;
        else cout<<"! "<<l<<endl;
        return;
    }
    else if(l==r-2)
    {
        if(pos==l)
        {
            pos=get(l+1,r);
            solve(l+1,r);
        }
        else if(pos==r)
        {
            pos=get(l,r-1);
            solve(l,r-1);
        }
        else
        {
            ll np=get(l,r-1);
            if(np==pos)cout<<"! "<<l<<endl;
            else cout<<"! "<<r<<endl;
        }
        return;
    }
    ll mid=t*l+(1-t)*r,np;
    if(pos<=mid)
    {
        np=get(l,mid);
        if(np==pos)solve(l,mid);
        else
        {
            pos=get(mid+1,r);
            solve(mid+1,r);
        }
    }
    else
    {
        mid=t*r+(1-t)*l;
        np=get(mid+1,r);
        if(np==pos)solve(mid+1,r);
        else
        {
            pos=get(l,mid);
            solve(l,mid);
        }
    }
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    ll T;
    cin>>T;
    while(T--)
    {
        cin>>n;
        cout<<"? "<<1<<" "<<n<<endl;
        cin>>pos;
        solve(1,n);
    }
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3584kb

input:

3
5
3
5
2
1

output:

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

result:

wrong answer Wrong prediction (test case 1)