結果

問題 No.2220 Range Insert & Point Mex
ユーザー kuronikuroni
提出日時 2023-02-17 21:54:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 392 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 1,939 ms
コンパイル使用メモリ 187,820 KB
実行使用メモリ 41,092 KB
最終ジャッジ日時 2023-09-28 18:01:16
合計ジャッジ時間 9,945 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 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,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 388 ms
41,084 KB
testcase_14 AC 386 ms
41,092 KB
testcase_15 AC 390 ms
41,084 KB
testcase_16 AC 379 ms
41,008 KB
testcase_17 AC 387 ms
40,984 KB
testcase_18 AC 383 ms
41,036 KB
testcase_19 AC 392 ms
41,040 KB
testcase_20 AC 116 ms
19,168 KB
testcase_21 AC 115 ms
19,140 KB
testcase_22 AC 114 ms
19,172 KB
testcase_23 AC 208 ms
24,628 KB
testcase_24 AC 192 ms
24,372 KB
testcase_25 AC 134 ms
19,120 KB
testcase_26 AC 178 ms
25,312 KB
testcase_27 AC 122 ms
13,956 KB
testcase_28 AC 57 ms
14,420 KB
testcase_29 AC 58 ms
14,372 KB
testcase_30 AC 59 ms
14,356 KB
testcase_31 AC 112 ms
20,672 KB
testcase_32 AC 104 ms
18,888 KB
testcase_33 AC 104 ms
18,380 KB
testcase_34 AC 169 ms
20,468 KB
testcase_35 AC 203 ms
19,872 KB
testcase_36 AC 169 ms
20,456 KB
testcase_37 AC 200 ms
19,964 KB
testcase_38 AC 214 ms
32,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:28:16: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   28 |     for (auto &[key, ve] : que) {
      |                ^
main.cpp:29:19: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   29 |         for (auto [t, v] : ve) {
      |                   ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    map<int, vector<pair<int, int>>> que;
    for (int i = 0; i < n; i++) {
        int l, r, v; cin >> l >> r >> v;
        if (v <= n) {
            que[l].push_back({0, v});
            que[r + 1].push_back({1, v});
        }
    }
    int q; cin >> q;
    for (int i = 0; i < q; i++) {
        int x; cin >> x;
        que[x].push_back({2, i});
    }
    
    set<int> mex;
    for (int i = 0; i <= n; i++) {
        mex.insert(i);
    }
    map<int, int> cnt;
    vector<int> ans(q);
    for (auto &[key, ve] : que) {
        for (auto [t, v] : ve) {
            if (t == 0) {
                if (cnt[v]++ == 0) {
                    mex.erase(v);
                }
            } else if (t == 1) {
                if (--cnt[v] == 0) {
                    mex.insert(v);
                }
            } else {
                ans[v] = *mex.begin();
            }
        }
    }
    for (int i = 0; i < q; i++) {
        cout << ans[i] << '\n';
    }
}
0