結果
問題 | No.1788 Same Set |
ユーザー | 👑 Nachia |
提出日時 | 2021-12-17 00:48:27 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,835 bytes |
コンパイル時間 | 1,088 ms |
コンパイル使用メモリ | 92,396 KB |
実行使用メモリ | 544,248 KB |
最終ジャッジ日時 | 2024-09-14 00:48:27 |
合計ジャッジ時間 | 35,097 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
21,860 KB |
testcase_01 | AC | 11 ms
21,856 KB |
testcase_02 | AC | 10 ms
21,792 KB |
testcase_03 | AC | 11 ms
21,896 KB |
testcase_04 | AC | 11 ms
22,008 KB |
testcase_05 | AC | 10 ms
21,932 KB |
testcase_06 | AC | 11 ms
22,232 KB |
testcase_07 | AC | 12 ms
22,204 KB |
testcase_08 | AC | 12 ms
22,204 KB |
testcase_09 | AC | 10 ms
21,856 KB |
testcase_10 | AC | 11 ms
21,832 KB |
testcase_11 | AC | 57 ms
52,432 KB |
testcase_12 | AC | 301 ms
128,748 KB |
testcase_13 | AC | 437 ms
172,528 KB |
testcase_14 | AC | 778 ms
290,512 KB |
testcase_15 | AC | 1,196 ms
469,924 KB |
testcase_16 | MLE | - |
testcase_17 | AC | 1,343 ms
474,732 KB |
testcase_18 | AC | 1,477 ms
495,408 KB |
testcase_19 | AC | 1,140 ms
464,484 KB |
testcase_20 | AC | 73 ms
52,500 KB |
testcase_21 | AC | 1,198 ms
467,956 KB |
testcase_22 | AC | 1,340 ms
483,980 KB |
testcase_23 | AC | 1,011 ms
373,756 KB |
testcase_24 | AC | 1,129 ms
380,544 KB |
testcase_25 | MLE | - |
testcase_26 | MLE | - |
testcase_27 | AC | 111 ms
54,272 KB |
testcase_28 | MLE | - |
testcase_29 | AC | 1,559 ms
494,736 KB |
testcase_30 | AC | 111 ms
54,656 KB |
testcase_31 | MLE | - |
testcase_32 | AC | 1,457 ms
467,700 KB |
testcase_33 | MLE | - |
testcase_34 | MLE | - |
testcase_35 | MLE | - |
testcase_36 | MLE | - |
testcase_37 | MLE | - |
testcase_38 | MLE | - |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) int segtree_N = 1 << 18; vector<int> segtree; vector<vector<pair<int,int>>> segtree_queries; vector<vector<pair<int,int>>> segtree_rollback; long long ans = 0; int N; vector<int> A; vector<int> B; vector<vector<int>> occurA; vector<vector<int>> occurB; void segtree_query(int l, int r, int t, int a=0, int b=0, int i=0){ if(i == 0){ a=0; b=segtree_N; i=1; } if(segtree[i] == 0) return; if(r <= a || b <= l) return; if(l <= a && b <= r){ segtree_rollback[t].push_back(make_pair(i,segtree[i])); segtree[i] = 0; return; } segtree_query(l, r, t, a, (a+b)/2, i*2); segtree_query(l, r, t, (a+b)/2, b, i*2+1); segtree_rollback[t].push_back(make_pair(i,segtree[i])); segtree[i] = segtree[i*2] + segtree[i*2+1]; } void run(int l, int r, int t){ for(auto [ql, qr] : segtree_queries[t]) segtree_query(ql, qr, t); if(l+1 == r){ if(t - segtree_N <= N){ //cout << "t = " << (t-segtree_N) << ", dans = " << (segtree[1] - (t-segtree_N)) << endl; ans += segtree[1] - (t-segtree_N); } } else{ run(l, (l+r)/2, t*2); run((l+r)/2, r, t*2+1); } reverse(segtree_rollback[t].begin(), segtree_rollback[t].end()); for(auto [i, v] : segtree_rollback[t]) segtree[i] = v; } void segtree_init(int n){ segtree_N = 1; while(segtree_N < n) segtree_N *= 2; segtree.assign(segtree_N * 2, 0); segtree_queries.assign(segtree_N * 2, {}); segtree_rollback.assign(segtree_N * 2, {}); for(int i=0; i<n; i++) segtree[segtree_N + i] = 1; for(int i=segtree_N-1; i>=1; i--) segtree[i] = segtree[i*2] + segtree[i*2+1]; } void segtree_dynamic_query(int l, int r, int tl, int tr){ tl += segtree_N; tr += segtree_N; while(tl < tr){ if(tl & 1) segtree_queries[tl++].push_back(make_pair(l,r)); if(tr & 1) segtree_queries[--tr].push_back(make_pair(l,r)); tl /= 2; tr /= 2; } } int main(){ cin >> N; A.resize(N); rep(i,N){ cin >> A[i]; A[i]--; } B.resize(N); rep(i,N){ cin >> B[i]; B[i]--; } segtree_init(N); occurA.resize(400000); occurB.resize(400000); rep(i,N) occurA[A[i]].push_back(i); rep(i,N) occurB[B[i]].push_back(i); rep(t,2){ swap(A, B); swap(occurA, occurB); rep(i,N){ int a = A[i]; if(B[i] == a) continue; auto r = lower_bound(occurB[a].begin(), occurB[a].end(), i) - occurB[a].begin(); int tl = 0; if(r != 0) tl = occurB[a][r-1] + 1; int tr = i+1; int ql = i; int qr = N; if(r != occurB[a].size()) qr = occurB[a][r]; //cout << "tl = " << tl << ", tr = " << tr << ", ql = " << ql << ", qr = " << qr << endl; segtree_dynamic_query(ql, qr, tl, tr); } } run(0, segtree_N, 1); cout << ans << endl; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;