結果

問題 No.2220 Range Insert & Point Mex
ユーザー karinohitokarinohito
提出日時 2023-02-17 22:13:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,693 bytes
コンパイル時間 4,740 ms
コンパイル使用メモリ 285,648 KB
実行使用メモリ 43,904 KB
最終ジャッジ日時 2024-07-19 13:22:54
合計ジャッジ時間 17,021 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 WA -
testcase_04 AC 2 ms
6,940 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
6,944 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 596 ms
43,904 KB
testcase_21 AC 590 ms
43,904 KB
testcase_22 AC 586 ms
43,904 KB
testcase_23 AC 361 ms
22,016 KB
testcase_24 AC 285 ms
21,760 KB
testcase_25 AC 274 ms
16,512 KB
testcase_26 AC 329 ms
22,144 KB
testcase_27 AC 105 ms
14,464 KB
testcase_28 AC 190 ms
11,008 KB
testcase_29 AC 189 ms
11,008 KB
testcase_30 AC 194 ms
10,880 KB
testcase_31 AC 276 ms
20,456 KB
testcase_32 AC 243 ms
17,392 KB
testcase_33 AC 267 ms
19,452 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 408 ms
31,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <cassert>
#include <cmath>
#include <complex>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (a == 0)return b;
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll sqrtz(ll N) {
    ll L = 0;
    ll R = sqrt(N) + 10000;
    while (abs(R - L) > 1) {
        ll mid = (R + L) / 2;
        if (mid * mid <= N)L = mid;
        else R = mid;
    }
    return L;

}


using mint = modint998244353;



/*
区間をsetで管理するテク
区間は半開区間で持たせる[L,R)
*/

ll cnt=0;
vll AN;
ll cm = 0;

template<class T>
struct rangeset {
    set<pair<T, T>> S;
    T INF;

    rangeset() {
        INF = 2e18;;
        S.insert({ INF,INF });
        S.insert({ -INF,-INF });
    }
    bool iscovered(T L, T R) {
        //assert(L<=R);
        auto itr = S.lower_bound({ L + 1,L + 1 });
        itr = prev(itr);
        auto st = *itr;
        return (itr->first <= L && R <= itr->second);
    }
    bool iscovered(T x) {
        return iscovered(x, x + 1);
    }
    pair<T, T> covered(T L, T R) {
        //assert(L<=R);
        auto itr = S.lower_bound({ L + 1,L + 1 });
        itr--;
        auto st = *itr;
        if (itr->first <= L && R <= itr->second) {
            return st;
        }
        else {
            return { INF,INF };
        }
    }
    pair<T, T> covered(T x) {
        return covered(x, x + 1);
    }
    T insert(T L, T R) {
        if (iscovered(L, R))return T(0);
        auto itr = S.lower_bound({ L + 1,L + 1 });
        itr = prev(itr);
        T res = T(0);
        auto st = *itr;
        if (itr->first <= L && L <= itr->second) {
            L = st.first;
            res -= itr->second - itr->first;
            itr = S.erase(itr);
        }
        else itr = next(itr);
        while (R > itr->second) {
            res -= itr->second - itr->first;
            itr = S.erase(itr);
        }
        if (itr->first <= R && R <= itr->second) {
            res -= itr->second - itr->first;
            R = itr->second;
            itr = S.erase(itr);
        }
        S.insert({ L,R });
        res += R - L;
        return res;
    }
    T insert(T x) {
        return insert(x, x + 1);
    }

    T erase(T L, T R) {
        auto itr = S.lower_bound({ L + 1,L + 1 });
        itr = prev(itr);
        T res = T(0);
        auto st = *itr;
        if (itr->first <= L && R <= itr->second) {
            if (itr->first < L)S.insert({ itr->first,L });
            if (R < itr->second)S.insert({ R,itr->second });
            for (ll p = L; p < R; p++) {
                AN[p] = cm;
                cnt++;
            }
            S.erase(itr);
            return R - L;
        }
        if (itr->first <= L && L < itr->second) {
            res += itr->second - L;
            if (itr->first < L)S.insert({ itr->first,L });
            for (ll p = L; p < itr->second; p++) {
                AN[p] = cm;
                cnt++;
            }
            itr = S.erase(itr);
        }
        else itr = next(itr);

        while (itr->second <= R) {
            res += itr->second - itr->first;
            for (ll p = itr->first; p < itr->second; p++) {
                AN[p] = cm;
                cnt++;
            }
            itr = S.erase(itr);
        }

        if (itr->first < R && R <= itr->second) {
            res += R - itr->first;
            if (R < itr->second)S.insert({ R,itr->second });
            for (ll p = itr->first; p < R; p++) {
                AN[p] = cm;
                cnt++;
            }
            S.erase(itr);
        }
        return res;
    }
    T erase(T x) {
        return erase(x, x + 1);
    }
};


int main() {

    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    rangeset<ll> S;
    map<ll, vector<pair<ll, ll>>> P;
    ll N;
    cin >> N;

    map<ll, ll> M;
    rep(i, N) {
        ll L, R, A;
        cin >> L >> R >> A;
        M[L] = M[R] = 1;
        P[A].push_back({ L,R });
    }
    ll Q;
    cin >> Q;
    vll X(Q);
    rep(i, Q) {
        ll x;
        cin >> x;
        M[x] = 1;
        X[i] = x;
    }

    ll m = 0;
    for (auto mm : M) {
        M[mm.first] = m;
        m++;
    }
    AN.assign(m, N);
    S.insert(0, m);

    rep(i,N){
        vector<pair<ll,ll>> NP;
        ll NL=-1;
        ll NR=-1;
        for(auto lr:P[i]){
            ll L=lr.first;
            ll R=lr.second;
            if(NR+1<L){
                if(NR!=-1)NP.push_back({NL,NR});
                NL=L;
                NR=R;
            }
            else{
                NR=R;
            }

        }
        if(NR!=-1){
            NP.push_back({NL,NR});
        }
        P[i]=NP;
    }
    rep(i, N + 1) {
        ll LL = 0;
        cm = i;
        for (auto lr : P[i]) {
            ll L = M[lr.first];
            ll R = M[lr.second];

            if (LL < L)S.erase(LL, L);
            LL = R + 1;
        }

        S.erase(LL, m + 1);
    }
    rep(q, Q) {
        cout << AN[M[X[q]]] << endl;
    }

   //cout<<cnt<<endl;
}
0