結果

問題 No.2220 Range Insert & Point Mex
ユーザー milanis48663220milanis48663220
提出日時 2023-02-17 22:19:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 343 ms / 2,000 ms
コード長 2,990 bytes
コンパイル時間 1,484 ms
コンパイル使用メモリ 128,344 KB
実行使用メモリ 30,016 KB
最終ジャッジ日時 2023-09-28 18:05:21
合計ジャッジ時間 9,961 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 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,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 335 ms
29,908 KB
testcase_14 AC 340 ms
29,968 KB
testcase_15 AC 343 ms
30,016 KB
testcase_16 AC 340 ms
29,908 KB
testcase_17 AC 338 ms
29,952 KB
testcase_18 AC 341 ms
29,912 KB
testcase_19 AC 342 ms
29,804 KB
testcase_20 AC 218 ms
23,556 KB
testcase_21 AC 221 ms
23,644 KB
testcase_22 AC 220 ms
23,620 KB
testcase_23 AC 227 ms
16,612 KB
testcase_24 AC 145 ms
15,984 KB
testcase_25 AC 196 ms
14,584 KB
testcase_26 AC 200 ms
14,264 KB
testcase_27 AC 43 ms
8,520 KB
testcase_28 AC 146 ms
9,260 KB
testcase_29 AC 150 ms
9,160 KB
testcase_30 AC 149 ms
9,280 KB
testcase_31 AC 192 ms
14,184 KB
testcase_32 AC 190 ms
13,868 KB
testcase_33 AC 190 ms
13,956 KB
testcase_34 AC 249 ms
19,132 KB
testcase_35 AC 253 ms
19,112 KB
testcase_36 AC 234 ms
15,384 KB
testcase_37 AC 238 ms
15,184 KB
testcase_38 AC 235 ms
24,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/segtree>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

template<typename T>
class Compress{
    public:
    vector<T> data;
    int offset;
    Compress(vector<T> data_, int offset=0): offset(offset){
        data = data_;
        sort(begin(data), end(data));
        data.erase(unique(begin(data), end(data)), end(data));
    };
    int operator[](T x) {
        auto p = lower_bound(data.begin(), data.end(), x);
        assert(x == *p);
        return offset+(p-data.begin());
	}
    T inv(int x){
        return data[x-offset];
    }
    int size(){
        return data.size();
    }
};

int op(int x, int y){
    return min(x, y);
}

const int inf = 1e9;

int e(){
    return inf;
}

using Seg = atcoder::segtree<int, op, e>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<int> l(n), r(n), a(n);
    vector<int> v;
    for(int i = 0; i < n; i++) {
        cin >> l[i] >> r[i] >> a[i]; l[i]--;
        v.push_back(l[i]);
        v.push_back(r[i]);
    }
    int q; cin >> q;
    vector<int> x(q);
    for(int i = 0; i < q; i++){
        cin >> x[i]; x[i]--;
        v.push_back(x[i]);
    }
    auto cp = Compress<int>(v);
    int m = cp.size();
    vector<vector<int>> adds(m);
    vector<vector<int>> dels(m);
    for(int i = 0; i < n; i++){
        if(a[i] >= n) continue;
        adds[cp[l[i]]].push_back(a[i]);
        dels[cp[r[i]]].push_back(a[i]);
    }
    Seg seg(vector<int>(n+1));
    vector<int> mex(m);
    for(int i = 0; i < m; i++){
        for(int x: dels[i]) seg.set(x, seg.get(x)-1);
        for(int x: adds[i]) seg.set(x, seg.get(x)+1);
        auto g = [&](int x){
            return x > 0;
        };
        int r = seg.max_right(0, g);
        mex[i] = r;
    }
    for(int i = 0; i < q; i++) cout << mex[cp[x[i]]] << endl;
}
0