QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#666983#7756. Omniscia Spares NonemikuTL 0ms0kbC++201000b2024-10-22 20:38:422024-10-22 20:38:48

Judging History

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

  • [2024-10-22 20:38:48]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-22 20:38:42]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define endl '\n'
using namespace std;
using ll =long long ;
using pii =pair<int,int>;
using pll=pair<ll,ll>;
const int N=5e5+10;
ll a[N];
ll b[N];
void solve(){
	int n;
	cin>>n;
	map<int,int>mp;
	map<pii,int>mpx;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int idx=0;deque<ll>dq;
	for(int i=1;i<=n;i++){
		cin>>b[i];
		mp[b[i]]=++idx;
	}
	for(int i=1;i<=n;i++){
		a[i]=mp[a[i]];dq.pb(a[i]);
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(a[i]>a[j])mpx[{a[i],a[j]}]=1;
		}
	}	
	for(int i=1;i<=n*(n-1);){
		if(mpx[{dq[0],dq[1]}]){
			mpx[{dq[0],dq[1]}]=0;
			dq.pb(dq[1]);dq.pb(dq[0]);
			dq.pop_front();cout<<2;i+=2;
		}
		else {dq.pb(dq[0]);i++;}
		cout<<1;
		dq.pop_front();
	}
	if(dq[0]!=1){
		int w=n-dq[0]+1;
		while(w--)cout<<1;
	}
	cout<<endl;
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int _=1;
	cin>>_;
	while(_--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3

output:


result: