QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#253607 | #6303. Inversion | SATSKY | WA | 45ms | 3812kb | C++20 | 1.8kb | 2023-11-17 09:58:08 | 2023-11-17 09:58:08 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;using ll=long long;const ll inf=3e18;const int M=1e9+7;
int o,o2,tc;
vector<int>res;
struct S
{
vector<int>arr,r2,rev;int n;
void ins(int id,int pos,int siz)
{
//cout<<siz<<':'<<pos<<'\n';
int pt=0;r2[pos]=id;
for(int i=1;i<=siz;i++)if(i!=pos)r2[i]=arr[++pt];
swap(arr,r2);
}
int query(int l,int r)
{
if(l>r)return 0;
cout<<"? "<<l<<" "<<r<<endl;
int x=0;
cin>>x;
//for(int i=l;i<r;i++)for(int j=i+1;j<=r;j++)x^=(res[i]>res[j]);
//cout<<l<<"#"<<r<<"#"<<x<<'\n';
return x;
}
bool chk(int a,int b)//a<b 0:r[a]<r[b] 1:r[a]>r[b]
{
bool sw=0;if(a>b)swap(a,b),sw=1;
bool x=query(a,b)^query(a+1,b)^query(a,b-1)^query(a+1,b-1);
//cout<<a<<"!!"<<b<<"!!"<<x<<'\n';
//if(bool(x)^(res[a]>res[b]))
//{
// cout<<a<<"!!"<<b<<"!!"<<x<<'\n';
//}
return x^sw;
}
void solve()
{
cin>>n;arr.resize(n+1),r2.resize(n+1);int kk;
vector<pair<int,int>>hs(n+1);hs[1]={74275,1};
for(int i=2;i<=n;i++)hs[i]={hs[i-1].first*hs[i-1].first+7,i};
sort(hs.begin()+1,hs.end());
//
//res.resize(n+1);for(int i=1;i<=n;i++)cin>>res[i];
//
arr[1]=hs[1].second;
for(int i=2;i<=n;i++)
{
int p=hs[i].second;
if(chk(arr[1],p)){ins(p,1,i);continue;}
if(!chk(arr[i-1],p)){ins(p,i,i);continue;}
int l=1,r=i;while(l<r-1)
{
int mid=(l+r)/2;chk(arr[mid],p)?r=mid:l=mid;
}
ins(p,r,i);
}
rev.resize(n+1);for(int i=1;i<=n;i++)rev[arr[i]]=i;
cout<<"!";for(int i=1;i<=n;i++)cout<<' '<<rev[i];cout<<endl;
}
};
int main()
{
//freopen("3.in","r",stdin);
//cout<<fixed<<setprecision(12);
//ios::sync_with_stdio(0);cin.tie(0);
int t=1;//cin>>t;o=(t>50);
//clock_t a=clock();
while(t--){S SS;SS.solve();}
//cout<<"Time:"<<double(clock()-a)<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3812kb
input:
3 0 0 0 0 0 0 0 1 0 0
output:
? 1 2 ? 2 2 ? 1 1 ? 1 2 ? 2 2 ? 1 1 ? 1 3 ? 2 3 ? 1 2 ? 2 2 ! 2 3 1
result:
ok OK, guesses=10
Test #2:
score: -100
Wrong Answer
time: 45ms
memory: 3644kb
input:
1993 0 0 1 0 1 0 1 0 1 1 0 1 1 1 0 1 0 0 0 1 0 1 0 0 1 1 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 1 0 0 1 0 0 0 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 0 0 0 0 1 0 1 0 0 0 1 0 1 0 1 0 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1 1 1 1 0 0 1 1 0 0 1 0 1 0 1 1 0 0 0 0 0 0 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0 0 1 1 1 1 0 1...
output:
? 9 11 ? 10 11 ? 9 10 ? 10 10 ? 11 15 ? 12 15 ? 11 14 ? 12 14 ? 9 15 ? 10 15 ? 9 14 ? 10 14 ? 9 15 ? 10 15 ? 9 14 ? 10 14 ? 11 17 ? 12 17 ? 11 16 ? 12 16 ? 17 19 ? 18 19 ? 17 18 ? 18 18 ? 19 21 ? 20 21 ? 19 20 ? 20 20 ? 9 21 ? 10 21 ? 9 20 ? 10 20 ? 19 23 ? 20 23 ? 19 22 ? 20 22 ? 21 23 ? 22 23 ? 21...
result:
wrong output format Unexpected end of file - int32 expected