QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#253606#6303. InversionSATSKYTL 0ms0kbC++201.8kb2023-11-17 09:55:572023-11-17 09:55:57

Judging History

你现在查看的是最新测评结果

  • [2023-11-17 09:55:57]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-11-17 09:55:57]
  • 提交

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;
		int 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 bool(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: 0
Time Limit Exceeded

input:

3

output:


result: