結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
34,516 KB
testcase_01 AC 15 ms
34,692 KB
testcase_02 AC 15 ms
34,588 KB
testcase_03 AC 15 ms
34,512 KB
testcase_04 AC 15 ms
34,548 KB
testcase_05 AC 17 ms
34,584 KB
testcase_06 AC 16 ms
34,584 KB
testcase_07 AC 16 ms
34,576 KB
testcase_08 AC 15 ms
34,528 KB
testcase_09 AC 17 ms
34,616 KB
testcase_10 AC 16 ms
34,560 KB
testcase_11 AC 16 ms
34,536 KB
testcase_12 AC 16 ms
34,536 KB
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 190 ms
39,064 KB
testcase_24 AC 163 ms
39,192 KB
testcase_25 AC 131 ms
37,568 KB
testcase_26 AC 148 ms
39,120 KB
testcase_27 AC 92 ms
37,796 KB
testcase_28 AC 72 ms
35,928 KB
testcase_29 AC 71 ms
35,900 KB
testcase_30 AC 71 ms
35,968 KB
testcase_31 RE -
testcase_32 AC 112 ms
36,328 KB
testcase_33 AC 113 ms
36,724 KB
testcase_34 AC 128 ms
36,548 KB
testcase_35 AC 130 ms
36,548 KB
testcase_36 AC 127 ms
36,496 KB
testcase_37 AC 130 ms
36,708 KB
testcase_38 AC 153 ms
39,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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