QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#858568#8939. PermutationMightZeroWA 3ms3584kbC++201.9kb2025-01-16 19:18:252025-01-16 19:18:30

Judging History

This is the latest submission verdict.

  • [2025-01-16 19:18:30]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 3584kb
  • [2025-01-16 19:18:25]
  • 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(mid<l)mid=l;
    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<<"? "<<l<<" "<<mid<<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;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3584kb

input:

3
5
3
3
6
6
3
1
4
3
3

output:

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

result:

ok Correct (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 3584kb

input:

10000
10
2
2
1
3
10
10
10
7
5
10
5
5
6
10
9

output:

? 1 10
? 1 4
? 1 2
? 3 4
! 4
? 1 10
? 5 10
? 7 10
? 5 6
! 6
? 1 10
? 5 10
? 5 6
? 7 10
? 9 10
? 7 8

result:

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