QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#858563 | #8939. Permutation | MightZero | WA | 0ms | 3584kb | C++20 | 1.9kb | 2025-01-16 19:16:04 | 2025-01-16 19:16:15 |
Judging History
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;
}
详细
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)