結果

問題 No.2220 Range Insert & Point Mex
ユーザー nika tamlianinika tamliani
提出日時 2023-02-17 23:17:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,172 bytes
コンパイル時間 2,167 ms
コンパイル使用メモリ 204,892 KB
実行使用メモリ 160,884 KB
最終ジャッジ日時 2023-09-26 20:38:38
合計ジャッジ時間 16,439 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
129,872 KB
testcase_01 AC 55 ms
129,680 KB
testcase_02 AC 56 ms
129,680 KB
testcase_03 AC 54 ms
129,616 KB
testcase_04 AC 55 ms
129,604 KB
testcase_05 AC 55 ms
129,656 KB
testcase_06 AC 57 ms
129,424 KB
testcase_07 AC 55 ms
129,596 KB
testcase_08 AC 55 ms
129,596 KB
testcase_09 AC 55 ms
129,408 KB
testcase_10 AC 55 ms
129,656 KB
testcase_11 AC 55 ms
129,672 KB
testcase_12 AC 56 ms
129,420 KB
testcase_13 RE -
testcase_14 WA -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 181 ms
149,156 KB
testcase_21 AC 183 ms
149,152 KB
testcase_22 AC 180 ms
149,332 KB
testcase_23 AC 227 ms
132,848 KB
testcase_24 AC 201 ms
132,820 KB
testcase_25 AC 171 ms
131,204 KB
testcase_26 AC 188 ms
132,768 KB
testcase_27 AC 131 ms
132,776 KB
testcase_28 AC 109 ms
129,616 KB
testcase_29 AC 109 ms
129,664 KB
testcase_30 AC 108 ms
129,652 KB
testcase_31 AC 201 ms
146,144 KB
testcase_32 AC 149 ms
130,220 KB
testcase_33 AC 149 ms
130,300 KB
testcase_34 AC 163 ms
130,452 KB
testcase_35 AC 169 ms
130,432 KB
testcase_36 AC 164 ms
130,160 KB
testcase_37 AC 169 ms
130,340 KB
testcase_38 AC 191 ms
133,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MOD = 998244353, oo = 1e9 + 10, N = 4e6 + 10;
int c[N][2], nodes = 1;
pair<int, int> t[N];
pair<int, int> neutral = {-1, -1};


pair<int, int> merge(pair<int, int> A, pair<int, int> B) {
    
    if (A == neutral) {
        return B;
    }
    
    if (B == neutral) {
        return A;
    }
    
    if (A.second >= B.first - 1) {
        return {min(B.first, A.first), max(B.second, A.second)};
    }
    return A;
}

void push(int pos) {
    if (c[pos][0] == 0) {
        c[pos][0] = ++nodes;
    }
    if (c[pos][1] == 0) {
        c[pos][1] = ++nodes;
    }
    t[c[pos][0]] = merge(t[c[pos][0]], t[pos]);
    t[c[pos][1]] = merge(t[c[pos][1]], t[pos]);
    t[pos] = neutral;
}

void update(int l, int r, int L, int R, int v, int pos) {
    if (l > R || L > r) {
        return;
    }
    
    if (L <= l && R >= r) {
        t[pos] = merge(t[pos], {v, v});
        return;
    }
    if (l < r) {
        int m = l + r >> 1;
        push(pos);
        update(l, m, L, R, v, c[pos][0]);
        update(m + 1, r, L, R, v, c[pos][1]);
    }
}

void update(int l, int r, int v) {
    update(1, oo - 1, l, r, v, 1);
}

int get(int l, int r, int x, int pos) {
    if (l > x || r < x) {
        return 0;
    }
    
    if (l == r) {
        if (t[pos].first <= 0) {
            return t[pos].second + 1;
        }
        return 0;
    }
    
    push(pos);
    int m = l + r >> 1;
    return get(l, m, x, c[pos][0]) + get(m + 1, r, x, c[pos][1]);
}

int get(int pos) {
    return get(1, oo - 1, pos, 1);
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    
    int n; cin >> n;
    
    for (int i = 0; i < N; ++i) {
        t[i] = neutral;
    }
    
    vector<vector<pair<int, int>>> queries(N);
    for (int i = 0; i < n; ++i) {
        int l, r, x; cin >> l >> r >> x;
        if (x < N) {
            queries[x].push_back({l, r});
        }
    }
    for (int i = 0; i < N; ++i) {
        for (auto [l, r] : queries[i]) {
            update(l, r, i);
        }
    }
    
    int q; cin >> q;
    for (int _ = 0; _ < q; ++_) {
        int x; cin >> x;
        cout << get(x) << '\n';
    }
}

 
0