結果

問題 No.2220 Range Insert & Point Mex
ユーザー nono00nono00
提出日時 2023-03-04 13:51:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 1,256 bytes
コンパイル時間 1,188 ms
コンパイル使用メモリ 94,192 KB
実行使用メモリ 10,812 KB
最終ジャッジ日時 2023-10-18 04:32:56
合計ジャッジ時間 12,262 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 203 ms
10,812 KB
testcase_14 AC 204 ms
10,812 KB
testcase_15 AC 204 ms
10,812 KB
testcase_16 AC 204 ms
10,812 KB
testcase_17 AC 204 ms
10,812 KB
testcase_18 AC 204 ms
10,812 KB
testcase_19 AC 203 ms
10,812 KB
testcase_20 AC 225 ms
10,812 KB
testcase_21 AC 225 ms
10,812 KB
testcase_22 AC 225 ms
10,812 KB
testcase_23 AC 219 ms
10,812 KB
testcase_24 AC 184 ms
10,284 KB
testcase_25 AC 139 ms
7,392 KB
testcase_26 AC 192 ms
10,812 KB
testcase_27 AC 155 ms
10,020 KB
testcase_28 AC 39 ms
4,348 KB
testcase_29 AC 52 ms
4,348 KB
testcase_30 AC 51 ms
4,348 KB
testcase_31 AC 161 ms
10,812 KB
testcase_32 AC 124 ms
8,424 KB
testcase_33 AC 126 ms
8,424 KB
testcase_34 AC 196 ms
10,812 KB
testcase_35 AC 198 ms
10,812 KB
testcase_36 AC 189 ms
10,812 KB
testcase_37 AC 189 ms
10,812 KB
testcase_38 AC 192 ms
10,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>

int main() {
    int n;
    std::cin >> n;
    std::vector<std::pair<int, int>> query;
    query.reserve(2 * n);
    for (int i = 0; i < n; i++) {
        int l, r, a;
        std::cin >> l >> r >> a;
        l--;
        query.emplace_back(l, a);
        query.emplace_back(r, ~a);
    }
    int q;
    int inf = 1e9 + 1;
    std::cin >> q;
    query.reserve(2 * n + q);
    for (int i = 0; i < q; i++) {
        int x;
        std::cin >> x;
        x--;
        query.emplace_back(x, inf);
    }
    std::sort(query.begin(), query.end());
    std::set<int> mex;
    for (int i = 0; i <= n; i++) {
        mex.insert(i);
    }
    std::vector<int> count(n + 1);
    for (auto [x, y]: query) {
        if (y == inf) {
            std::cout << *mex.begin() << '\n';
        } else if (y >= 0) {
            if (y < n) {
                count[y]++;
                if (count[y] == 1) {
                    mex.erase(y);
                }
            }
        } else {
            y = ~y;
            if (y < n) {
                count[y]--;
                if (count[y] == 0) {
                    mex.insert(y);
                }
            }
        }
    }
}
0