結果

問題 No.2220 Range Insert & Point Mex
ユーザー jianglyjiangly
提出日時 2023-02-17 21:36:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 2,471 ms
コンパイル使用メモリ 215,716 KB
実行使用メモリ 14,112 KB
最終ジャッジ日時 2023-09-28 18:00:08
合計ジャッジ時間 7,596 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 111 ms
12,712 KB
testcase_14 AC 111 ms
13,520 KB
testcase_15 AC 112 ms
14,112 KB
testcase_16 AC 111 ms
13,044 KB
testcase_17 AC 111 ms
12,840 KB
testcase_18 AC 113 ms
12,480 KB
testcase_19 AC 111 ms
13,800 KB
testcase_20 AC 115 ms
12,288 KB
testcase_21 AC 115 ms
12,580 KB
testcase_22 AC 116 ms
12,272 KB
testcase_23 AC 136 ms
12,684 KB
testcase_24 AC 110 ms
11,524 KB
testcase_25 AC 84 ms
8,236 KB
testcase_26 AC 115 ms
12,908 KB
testcase_27 AC 98 ms
10,472 KB
testcase_28 AC 20 ms
5,348 KB
testcase_29 AC 23 ms
5,220 KB
testcase_30 AC 24 ms
5,228 KB
testcase_31 AC 89 ms
12,384 KB
testcase_32 AC 78 ms
9,588 KB
testcase_33 AC 79 ms
9,680 KB
testcase_34 AC 121 ms
12,316 KB
testcase_35 AC 122 ms
12,208 KB
testcase_36 AC 120 ms
12,952 KB
testcase_37 AC 120 ms
12,776 KB
testcase_38 AC 120 ms
13,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int n;
    std::cin >> n;
    
    std::vector<std::tuple<int, int, int>> events;
    for (int i = 0; i < n; i++) {
        int l, r, a;
        std::cin >> l >> r >> a;
        l--;
        events.emplace_back(l, 0, a);
        events.emplace_back(r, -1, a);
    }
    
    int q;
    std::cin >> q;
    
    std::vector<int> ans(q);
    for (int i = 0; i < q; i++) {
        int x;
        std::cin >> x;
        x--;
        events.emplace_back(x, 1, i);
    }
    
    std::vector<int> cnt(n + 1);
    std::set<int> ex;
    for (int i = 0; i <= n; i++) {
        ex.insert(i);
    }
    std::sort(events.begin(), events.end());
    
    for (auto [_, t, x] : events) {
        if (t == -1) {
            if (x <= n && --cnt[x] == 0) {
                ex.insert(x);
            }
        } else if (t == 0) {
            if (x <= n && cnt[x]++ == 0) {
                ex.erase(x);
            }
        } else {
            ans[x] = *ex.begin();
        }
    }
    for (int i = 0; i < q; i++) {
        std::cout << ans[i] << "\n";
    }
    
    return 0;
}
0