結果

問題 No.2220 Range Insert & Point Mex
ユーザー merom686merom686
提出日時 2023-02-17 22:28:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 1,163 bytes
コンパイル時間 2,406 ms
コンパイル使用メモリ 212,040 KB
実行使用メモリ 13,656 KB
最終ジャッジ日時 2023-09-28 18:07:39
合計ジャッジ時間 7,402 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 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,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 110 ms
12,496 KB
testcase_14 AC 109 ms
13,028 KB
testcase_15 AC 111 ms
12,484 KB
testcase_16 AC 109 ms
13,180 KB
testcase_17 AC 108 ms
12,948 KB
testcase_18 AC 110 ms
12,360 KB
testcase_19 AC 111 ms
12,680 KB
testcase_20 AC 87 ms
9,696 KB
testcase_21 AC 88 ms
9,704 KB
testcase_22 AC 86 ms
9,504 KB
testcase_23 AC 123 ms
12,988 KB
testcase_24 AC 100 ms
11,272 KB
testcase_25 AC 79 ms
8,168 KB
testcase_26 AC 115 ms
13,656 KB
testcase_27 AC 96 ms
10,336 KB
testcase_28 AC 19 ms
4,704 KB
testcase_29 AC 22 ms
4,636 KB
testcase_30 AC 21 ms
4,688 KB
testcase_31 AC 88 ms
12,300 KB
testcase_32 AC 67 ms
9,588 KB
testcase_33 AC 75 ms
9,284 KB
testcase_34 AC 102 ms
11,064 KB
testcase_35 AC 109 ms
11,256 KB
testcase_36 AC 100 ms
11,292 KB
testcase_37 AC 108 ms
11,144 KB
testcase_38 AC 115 ms
12,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct P {
    bool operator<(const P &p) const {
        return i != p.i ? i < p.i : abs(d) > abs(p.d);
    }
    int a, i, d;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<P> p;
    for (int i = 0; i < n; i++) {
        int l, r, a;
        cin >> l >> r >> a;
        l--;

        if (a < n) {
            p.push_back({ a, l, +1 });
            p.push_back({ a, r, -1 });
        }
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        int x;
        cin >> x;
        x--;

        p.push_back({ i, x, 0 });
    }
    sort(p.begin(), p.end());

    vector<int> r(q);
    vector<int> c(n, 0);
    set<int> st;
    for (int i = 0; i <= n; i++) {
        st.insert(i);
    }
    for (const auto &[a, i, d] : p) {
        if (d == 0) {
            r[a] = *st.begin();
        } else {
            if (c[a] == 0 && d == +1) st.erase(a);
            if (c[a] == 1 && d == -1) st.insert(a);
            c[a] += d;
        }
    }

    for (int i = 0; i < q; i++) {
        cout << r[i] << '\n';
    }

    return 0;
}
0