結果

問題 No.2220 Range Insert & Point Mex
ユーザー nika tamlianinika tamliani
提出日時 2023-02-17 23:18:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 561 ms / 2,000 ms
コード長 2,172 bytes
コンパイル時間 2,305 ms
コンパイル使用メモリ 205,844 KB
実行使用メモリ 369,524 KB
最終ジャッジ日時 2023-09-28 18:15:17
合計ジャッジ時間 15,592 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 243 ms
317,224 KB
testcase_01 AC 138 ms
317,332 KB
testcase_02 AC 137 ms
317,316 KB
testcase_03 AC 136 ms
317,148 KB
testcase_04 AC 136 ms
317,148 KB
testcase_05 AC 136 ms
317,092 KB
testcase_06 AC 137 ms
317,304 KB
testcase_07 AC 135 ms
317,144 KB
testcase_08 AC 135 ms
317,144 KB
testcase_09 AC 133 ms
317,216 KB
testcase_10 AC 136 ms
317,100 KB
testcase_11 AC 136 ms
317,384 KB
testcase_12 AC 134 ms
317,176 KB
testcase_13 AC 561 ms
369,392 KB
testcase_14 AC 552 ms
369,388 KB
testcase_15 AC 541 ms
369,332 KB
testcase_16 AC 546 ms
369,524 KB
testcase_17 AC 546 ms
369,204 KB
testcase_18 AC 545 ms
369,288 KB
testcase_19 AC 543 ms
369,220 KB
testcase_20 AC 258 ms
336,860 KB
testcase_21 AC 267 ms
336,840 KB
testcase_22 AC 262 ms
336,988 KB
testcase_23 AC 324 ms
320,204 KB
testcase_24 AC 293 ms
320,472 KB
testcase_25 AC 261 ms
319,024 KB
testcase_26 AC 273 ms
320,312 KB
testcase_27 AC 208 ms
320,188 KB
testcase_28 AC 197 ms
317,272 KB
testcase_29 AC 188 ms
317,384 KB
testcase_30 AC 190 ms
317,212 KB
testcase_31 AC 286 ms
333,644 KB
testcase_32 AC 241 ms
317,876 KB
testcase_33 AC 243 ms
317,880 KB
testcase_34 AC 264 ms
318,080 KB
testcase_35 AC 262 ms
318,000 KB
testcase_36 AC 258 ms
317,932 KB
testcase_37 AC 262 ms
318,136 KB
testcase_38 AC 285 ms
320,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MOD = 998244353, oo = 1e9 + 10, N = 1e7 + 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