結果
問題 |
No.1788 Same Set
|
ユーザー |
|
提出日時 | 2022-08-03 07:32:09 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 469 ms / 4,000 ms |
コード長 | 1,346 bytes |
コンパイル時間 | 11,815 ms |
コンパイル使用メモリ | 551,148 KB |
実行使用メモリ | 20,864 KB |
最終ジャッジ日時 | 2024-07-26 19:49:55 |
合計ジャッジ時間 | 20,257 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
コンパイルメッセージ
main.cpp:29:13: warning: operator '>>' has lower precedence than '+'; '+' will be evaluated first [-Wshift-op-parentheses] 29 | int mid=tl+tr>>1; | ~~^~~~~ main.cpp:29:13: note: place parentheses around the '+' expression to silence this warning 29 | int mid=tl+tr>>1; | ^ | ( ) 1 warning generated.
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 4e5; int N, A[MAXN+10], B[MAXN+10]; int PA[MAXN+10], PB[MAXN+10]; struct SEG { pii tree[MAXN*4+10]; void update(int node, int tl, int tr, int l, int r, int k) { if(l>r) return; if(r<tl || tr<l) return; if(l<=tl && tr<=r) { tree[node].first+=k; if(tree[node].first) tree[node].second=tr-tl+1; else if(tl==tr) tree[node].second=0; else tree[node].second=tree[node*2].second+tree[node*2+1].second; return; } int mid=tl+tr>>1; update(node*2, tl, mid, l, r, k); update(node*2+1, mid+1, tr, l, r, k); if(tree[node].first) tree[node].second=tr-tl+1; else tree[node].second=tree[node*2].second+tree[node*2+1].second; } }seg; int main() { scanf("%d", &N); for(int i=1; i<=N; i++) scanf("%d", &A[i]); for(int i=1; i<=N; i++) scanf("%d", &B[i]); ll ans=0; for(int i=1; i<=N; i++) { int l, r; vector<int> V; V.push_back(A[i]); if(A[i]!=B[i]) V.push_back(B[i]); for(auto it : V) { l=PA[it]; r=PB[it]; if(l>r) swap(l, r); seg.update(1, 1, N, l+1, r, -1); } PA[A[i]]=i; PB[B[i]]=i; for(auto it : V) { l=PA[it]; r=PB[it]; if(l>r) swap(l, r); seg.update(1, 1, N, l+1, r, 1); } ans+=i-seg.tree[1].second; } printf("%lld\n", ans); }