結果

問題 No.1788 Same Set
ユーザー 👑 hitonanodehitonanode
提出日時 2021-12-17 01:15:31
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 906 ms / 4,000 ms
コード長 2,298 bytes
コンパイル時間 1,441 ms
コンパイル使用メモリ 131,448 KB
実行使用メモリ 74,656 KB
最終ジャッジ日時 2023-10-12 01:32:45
合計ジャッジ時間 21,891 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 108 ms
16,188 KB
testcase_12 AC 256 ms
24,248 KB
testcase_13 AC 313 ms
26,616 KB
testcase_14 AC 437 ms
29,016 KB
testcase_15 AC 566 ms
29,248 KB
testcase_16 AC 606 ms
29,696 KB
testcase_17 AC 825 ms
61,032 KB
testcase_18 AC 815 ms
48,304 KB
testcase_19 AC 697 ms
74,656 KB
testcase_20 AC 175 ms
16,628 KB
testcase_21 AC 618 ms
29,268 KB
testcase_22 AC 652 ms
29,632 KB
testcase_23 AC 489 ms
26,520 KB
testcase_24 AC 602 ms
28,712 KB
testcase_25 AC 771 ms
32,676 KB
testcase_26 AC 785 ms
32,480 KB
testcase_27 AC 322 ms
23,936 KB
testcase_28 AC 860 ms
37,660 KB
testcase_29 AC 836 ms
37,540 KB
testcase_30 AC 318 ms
23,812 KB
testcase_31 AC 844 ms
37,588 KB
testcase_32 AC 854 ms
46,052 KB
testcase_33 AC 865 ms
46,408 KB
testcase_34 AC 906 ms
46,212 KB
testcase_35 AC 891 ms
47,548 KB
testcase_36 AC 890 ms
47,344 KB
testcase_37 AC 895 ms
47,304 KB
testcase_38 AC 887 ms
47,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;

#include <atcoder/lazysegtree>
using S = pair<int, int>;  // min, num of min
S op(S l, S r) {
    if (l.first < r.first) return l;
    if (l.first > r.first) return r;
    return {l.first, l.second + r.second};
}
S e() { return {1 << 20, 0}; }
using F = int;
S mapping(F f, S x) { return {x.first + f, x.second}; }
F composition(F f, F g) { return f + g; }
F id() { return 0; }

int main() {
    int N;
    cin >> N;

    vector<vector<tuple<int, int, int>>> updates(N + 1);

    unordered_map<int, pair<vector<int>, vector<int>>> mp;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        mp[a].first.push_back(i);
    }
    for (int i = 0; i < N; ++i) {
        int b;
        cin >> b;
        mp[b].second.push_back(i);
    }

    for (const auto &[key, xaxb] : mp) {
        const auto &[xa, xb] = xaxb;
        int ia = 0, ib = 0, l = 0;
        while (ia < int(xa.size()) or ib < int(xb.size())) {
            if (ia == xa.size()) {
                updates[l].emplace_back(xb[ib], N, 1);
                updates[xb[ib] + 1].emplace_back(xb[ib], N, -1);
                ib++;
            } else if (ib == xb.size()) {
                updates[l].emplace_back(xa[ia], N, 1);
                updates[xa[ia] + 1].emplace_back(xa[ia], N, -1);
                ia++;
            } else if (xa[ia] == xb[ib]) {
                l = xa[ia] + 1;
                ia++;
                ib++;
            } else if (xa[ia] < xb[ib]) {
                updates[l].emplace_back(xa[ia], xb[ib], 1);
                updates[xa[ia] + 1].emplace_back(xa[ia], xb[ib], -1);
                l = xa[ia] + 1;
                ia++;
            } else {
                updates[l].emplace_back(xb[ib], xa[ia], 1);
                updates[xb[ib] + 1].emplace_back(xb[ib], xa[ia], -1);
                l = xb[ib] + 1;
                ib++;
            }
        }
    }

    long long ret = 0;
    atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> tree(vector<S>(N, S(0, 1)));
    for (int i = 0; i < N; ++i) {
        for (auto [l, r, v] : updates[i]) tree.apply(l, r, v);
        auto pr = tree.prod(i, N);
        if (pr.first == 0) ret += pr.second;
    }
    cout << ret << '\n';
}
0