結果

問題 No.1698 Face to Face
ユーザー 沙耶花沙耶花
提出日時 2021-10-01 23:45:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,239 bytes
コンパイル時間 4,712 ms
コンパイル使用メモリ 278,388 KB
実行使用メモリ 40,704 KB
最終ジャッジ日時 2023-09-26 23:12:59
合計ジャッジ時間 16,007 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1,972 ms
34,556 KB
testcase_04 AC 1,838 ms
35,500 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

int main(){
	
	int N;
	cin>>N;
	
	vector<int> a(N),b(N),z(N);
	vector<int> posa(N),posb(N);
	rep(i,N){
		cin>>a[i];
		a[i]--;
		posa[a[i]] = i;
	}
	rep(i,N){
		cin>>b[i];
		b[i]--;
		posb[b[i]] = i;
	}
	vector<int> rz(N);
	rep(i,N){
		cin>>z[i];
		z[i]--;
		rz[z[i]] = i;
	}
	
	vector<int> ok(N,N),ng(N,-1);
	vector<vector<int>> qs(N);
	rep(_,18){

		qs.assign(N,vector<int>());
		rep(i,N){
			if(ok[i]-ng[i]==1)continue;
			qs[(ok[i]+ng[i])/2].push_back(i);
		}
		
		vector<int> pa(N),pb(N);
		rep(i,N){
			pa[i] = i;
			pb[i] = i;
		}
		vector<vector<int>> inda(N),indb(N);
		rep(i,N){
			inda[i].push_back(i);
			indb[i].push_back(i);
		}
		map<pair<int,int>,int> mp;
		rep(i,N){
			mp[make_pair(posa[i],posb[z[i]])]++;
		}
		
		rep(i,N){
			rep(j,qs[i].size()){
				int q = qs[i][j];
				int X = pa[q],Y = pb[q];
				if(mp.count(make_pair(X,Y)))ok[q] = i;
				else ng[q] = i;
			}
			
			int A = posa[i];
			if(A!=0 && a[A]>a[A-1]){
				int x = pa[A],y = pa[A-1];
				if(inda[x].size()>inda[y].size())swap(x,y);
				while(inda[x].size()>0){
					int ba = inda[x].back();
					inda[x].pop_back();
					int v = a[ba];
					mp[make_pair(pa[posa[v]],pb[posb[z[v]]])]--;
					if(mp[make_pair(pa[posa[v]],pb[posb[z[v]]])]==0)mp.erase(make_pair(pa[posa[v]],pb[posb[z[v]]]));
					pa[ba] = y;
					inda[y].push_back(ba);
					mp[make_pair(pa[posa[v]],pb[posb[z[v]]])]++;
				}
			}
			if(A!=N-1 && a[A]>a[A+1]){
				int x = pa[A],y = pa[A+1];
				if(inda[x].size()>inda[y].size())swap(x,y);
				while(inda[x].size()>0){
					int ba = inda[x].back();
					inda[x].pop_back();
					int v = a[ba];
					mp[make_pair(pa[posa[v]],pb[posb[z[v]]])]--;
					if(mp[make_pair(pa[posa[v]],pb[posb[z[v]]])]==0)mp.erase(make_pair(pa[posa[v]],pb[posb[z[v]]]));
					pa[ba] = y;
					inda[y].push_back(ba);
					mp[make_pair(pa[posa[v]],pb[posb[z[v]]])]++;
				}
			}
			
			A = posb[i];
			if(A!=0 && b[A]>b[A-1]){
				int x = pb[A],y = pb[A-1];
				if(indb[x].size()>indb[y].size())swap(x,y);
				while(indb[x].size()>0){
					int ba = indb[x].back();
					indb[x].pop_back();
					int v = b[ba];
					mp[make_pair(pa[posa[rz[v]]],pb[posb[v]])]--;
					if(mp[make_pair(pa[posa[rz[v]]],pb[posb[v]])]==0)mp.erase(make_pair(pa[posa[rz[v]]],pb[posb[v]]));
					pb[ba] = y;
					indb[y].push_back(ba);
					mp[make_pair(pa[posa[rz[v]]],pb[posb[v]])]++;
				}
			}
			if(A!=N-1 && b[A]>b[A+1]){
				int x = pb[A],y = pb[A+1];
				if(indb[x].size()>indb[y].size())swap(x,y);
				while(indb[x].size()>0){
					int ba = indb[x].back();
					indb[x].pop_back();
					int v = b[ba];
					mp[make_pair(pa[posa[rz[v]]],pb[posb[v]])]--;
					if(mp[make_pair(pa[posa[rz[v]]],pb[posb[v]])]==0)mp.erase(make_pair(pa[posa[rz[v]]],pb[posb[v]]));
					pb[ba] = y;
					indb[y].push_back(ba);
					mp[make_pair(pa[posa[rz[v]]],pb[posb[v]])]++;
				}
			}
			
			
			
		}
		
	}
	
	vector<int> ans(N+1,0);
	rep(i,N){
		//cout<<ok[i]<<endl;
		ans[ok[i]]++;
	}
	
	rep(i,N){
		ans[i+1] += ans[i];
	}
	
	for(int i=1;i<=N;i++){
		printf("%d\n",ans[i]);
	}
	
	return 0;
}
0