QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#96471 | #6303. Inversion | Liberty12619 | WA | 3ms | 3296kb | C++20 | 1.1kb | 2023-04-13 21:51:27 | 2023-04-13 21:52:13 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
const int N = 2e3+10,mod = 998244353,INF=1e9+10;
const double eps = 1e-8;
typedef pair<int,int>PII;
typedef pair<int,PII>PIII;
int pos[N],a[N];
int query(int l,int r)
{
cout<<"? "<<l<<" "<<r<<endl;
int x;
cin>>x;
return x;
}
bool check(int mid,int x)
{
int cnt=0;
for(int i=pos[mid]+1;i<x;i++)
if(a[i]<mid) cnt++;
int ans = ((query(pos[mid],x)-query(pos[mid]+1,x)-cnt)%2+2)%2;
return ans;
}
void solve()
{
int n;
cin>>n;
if(n==1)
{
cout<<"! "<<1<<endl;
return;
}
a[1]=1,pos[1]=1;
for(int i=2;i<=n;i++)
{
int l=0,r=i;
while(l<r)
{
int mid = l+r>>1;
if(check(mid,i)) r=mid;
else l=mid+1;
}
for(int j=i-1;j>=l;j--) a[pos[j]]++,pos[j+1]=pos[j];
pos[l]=i,a[i]=l;
}
cout<<"! ";
for(int i=1;i<=n;i++) cout<<a[i]<<" ";
cout<<endl;
}
signed main()
{
int T =1 ;
while(T--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 3296kb
input:
3 0 0 0 1
output:
? 1 2 ? 2 2 ? 1 3 ? 2 3 ? 0 3
result:
wrong output format Unexpected end of file - int32 expected