結果
問題 | No.1698 Face to Face |
ユーザー | 沙耶花 |
提出日時 | 2021-10-02 00:00:47 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,265 bytes |
コンパイル時間 | 4,975 ms |
コンパイル使用メモリ | 282,340 KB |
実行使用メモリ | 95,920 KB |
最終ジャッジ日時 | 2024-07-19 17:23:23 |
合計ジャッジ時間 | 63,252 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 891 ms
46,852 KB |
testcase_04 | AC | 846 ms
47,008 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 856 ms
48,324 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | AC | 2 ms
6,940 KB |
testcase_36 | WA | - |
testcase_37 | AC | 2 ms
6,940 KB |
testcase_38 | AC | 2 ms
6,940 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | AC | 2 ms
6,944 KB |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
ソースコード
#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); vector<vector<int>> Add(N),Del(N); vector<pair<int,int>> Ps; { 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); } rep(i,N){ Ps.emplace_back(posa[i],posb[z[i]]); } vector<vector<pair<int,int>>> AP(N),DP(N); rep(i,N){ 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]; DP[i].emplace_back(pa[posa[v]],pb[posb[z[v]]]); Ps.emplace_back(pa[posa[v]],pb[posb[z[v]]]); pa[ba] = y; inda[y].push_back(ba); AP[i].emplace_back(pa[posa[v]],pb[posb[z[v]]]); Ps.emplace_back(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]; DP[i].emplace_back(pa[posa[v]],pb[posb[z[v]]]); Ps.emplace_back(pa[posa[v]],pb[posb[z[v]]]); pa[ba] = y; inda[y].push_back(ba); AP[i].emplace_back(pa[posa[v]],pb[posb[z[v]]]); Ps.emplace_back(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]; DP[i].emplace_back(pa[posa[rz[v]]],pb[posb[v]]); Ps.emplace_back(pa[posa[rz[v]]],pb[posb[v]]); pb[ba] = y; indb[y].push_back(ba); AP[i].emplace_back(pa[posa[rz[v]]],pb[posb[v]]); Ps.emplace_back(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]; DP[i].emplace_back(pa[posa[rz[v]]],pb[posb[v]]); Ps.emplace_back(pa[posa[rz[v]]],pb[posb[v]]); pb[ba] = y; indb[y].push_back(ba); AP[i].emplace_back(pa[posa[rz[v]]],pb[posb[v]]); Ps.emplace_back(pa[posa[rz[v]]],pb[posb[v]]); } } } sort(Ps.begin(),Ps.end()); Ps.erase(unique(Ps.begin(),Ps.end()),Ps.end()); rep(i,N){ rep(j,AP[i].size()){ Add[i].push_back(distance(Ps.begin(),lower_bound(Ps.begin(),Ps.end(),AP[i][j]))); } rep(j,DP[i].size()){ Del[i].push_back(distance(Ps.begin(),lower_bound(Ps.begin(),Ps.end(),DP[i][j]))); } } } 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); } vector<int> cnt(Ps.size(),0); rep(i,N){ cnt[distance(Ps.begin(),lower_bound(Ps.begin(),Ps.end(),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]; int d = distance(Ps.begin(),lower_bound(Ps.begin(),Ps.end(),make_pair(X,Y))); if(d==Ps.size()||Ps[d]!=make_pair(X,Y)||cnt[d]==0){ ng[q] = i; } else{ ok[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(); pa[ba] = y; inda[y].push_back(ba); } } 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(); pa[ba] = y; inda[y].push_back(ba); } } 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(); pb[ba] = y; indb[y].push_back(ba); } } 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(); pb[ba] = y; indb[y].push_back(ba); } } rep(j,Add[i].size())cnt[Add[i][j]]++; rep(j,Del[i].size())cnt[Del[i][j]]--; } } 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; }