QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#858563#8939. PermutationMightZeroWA 0ms3584kbC++201.9kb2025-01-16 19:16:042025-01-16 19:16:15

Judging History

This is the latest submission verdict.

  • [2025-01-16 19:16:15]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3584kb
  • [2025-01-16 19:16:04]
  • 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;
void solve(ll l,ll r)
{
    if(l==r)
    {
        cout<<"! "<<l<<endl;
        return;
    }
    if(l==r-1)
    {
        if(pos==l)cout<<"! "<<r<<endl;
        else cout<<"! "<<l<<endl;
        return;
    }
    ll mid=t*l+(1-t)*r,np;
    if(mid>=r)mid=r-1;
    if(pos<=mid)
    {
        if(l==mid)
        {
            solve(mid+1,r);
            return;
        }
        cout<<"? "<<l<<" "<<mid<<endl;
        cin>>np;
        if(np==pos)solve(l,mid);
        else
        {
            if(mid+1!=r)
            {
                cout<<"? "<<mid+1<<" "<<r<<endl;
                cin>>pos;
            }
            solve(mid+1,r);
        }
    }
    else
    {
        if(r==mid+1)
        {
            solve(l,mid);
            return;
        }
        cout<<"? "<<mid+1<<" "<<r<<endl;
        cin>>np;
        if(np==pos)solve(mid+1,r);
        else
        {
            if(mid!=l)
            {
                cout<<"? "<<mid<<" "<<l<<endl;
                cin>>pos;
            }
            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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
5
3
3
6
6
3

output:

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

result:

wrong answer Integer 1 violates the range [3, 6] (test case 2)