結果

問題 No.2421 entersys?
ユーザー ayataka5ayataka5
提出日時 2023-08-12 15:09:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 5,176 bytes
コンパイル時間 3,361 ms
コンパイル使用メモリ 235,432 KB
実行使用メモリ 42,268 KB
最終ジャッジ日時 2024-11-20 00:04:13
合計ジャッジ時間 32,222 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
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 AC 587 ms
34,852 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};

int main() {
    int N;
    cin >> N;
    vector X(N, ""s);
    vector L(N, 0), R(N, 0);
    for(int i = 0; i < N; i++) {
        cin >> X[i] >> L[i] >> R[i];
    }
    int Q;
    cin >> Q;
    vector q(Q, 0), t1(0, 0), t2(0, 0), l3(0, 0), r3(0, 0);
    vector x1(0, ""s), x3(0, ""s);
    for(int i = 0; i < Q; i++) {
        cin >> q[i];
        if(q[i] == 1) {
            string x;
            int t;
            cin >> x >> t;
            x1.push_back(x);
            t1.push_back(t);
        }
        if(q[i] == 2) {
            int t;
            cin >> t;
            t2.push_back(t);
        }
        if(q[i] == 3) {
            string x;
            int l, r;
            cin >> x >> l >> r;
            x3.push_back(x);
            l3.push_back(l);
            r3.push_back(r);
        }
    }

    vector P(0, 0);
    for(int i = 0; i < N; i++) {
        P.push_back(L[i]);
        P.push_back(R[i]);
    }
    for(int i = 0; i < t1.size(); i++) {
        P.push_back(t1[i]);
    }
    for(int i = 0; i < t2.size(); i++) {
        P.push_back(t2[i]);
    }
    for(int i = 0; i < l3.size(); i++) {
        P.push_back(l3[i]);
        P.push_back(r3[i]);
    }
    vector PP(P);
    sort(begin(PP), end(PP));
    PP.erase(unique(begin(PP), end(PP)), end(PP));
    int NN(PP.size());
    for(int i = 0; i < P.size(); i++) {
        P[i] = lower_bound(begin(PP), end(PP), P[i]) - begin(PP);
    }

    for(int i = 0; i < N; i++) {
        L[i] = P[i*2];
        R[i] = P[i*2+1];
    }
    for(int i = 0; i < t1.size(); i++) {
        t1[i] = P[N*2 + i];
    }
    for(int i = 0; i < t2.size(); i++) {
        t2[i] = P[N*2 + t1.size() + i];
    }
    for(int i = 0; i < l3.size(); i++) {
        l3[i] = P[N*2 + t1.size() + t2.size() + i*2];
        r3[i] = P[N*2 + t1.size() + t2.size() + i*2+1];
    }
    map<string, vector<pair<int, int>>> mp;
    for(int i = 0; i < N; i++) {
        mp[X[i]].push_back({L[i], R[i]});
    }
    LazySegmentTree seg( vector<ll>(NN, 0) );
    for(int i = 0; i < N; i++) {
        seg.add(L[i], R[i]+1, 1);
    }
    int idx1(0), idx2(0), idx3(0);
    for(int i = 0; i < Q; i++) {
        if(q[i] == 1) {
            string ans("No");
            vector V(mp[x1[idx1]]);
            /*
            cerr << '!';
            for(auto [x, y] : V) {
                cerr << " : ";
                cerr << x << ' ' << y;
            }
            cerr << endl;
            cerr << "!! " << t1[idx1] << endl;
            */
            if(t1[idx1] < V[0].first) {
                ans = "No";
            }else {
                int M(V.size());
                if(V[M-1].first <= t1[idx1] && t1[idx1] <= V[M-1].second) {
                    ans = "Yes";
                }else if(V[M-1].second < t1[idx1]) {
                    ans = "No";
                }else {
                    int ok(0), ng(M);
                    while(1 < ng-ok) {
                        int mid = (ok+ng)/2;
                        if(V[mid].first <= t1[idx1]) ok = mid;
                        else ng = mid;
                    }
                    /* cout << V[ok].first << ' ' << V[ok].second << endl; */
                    if(V[ok].first <= t1[idx1] && t1[idx1] <= V[ok].second) {
                        ans = "Yes";
                    }else {
                        ans = "No";
                    }
                }
            }
            cout << ans << endl;
            idx1++;
        }
        if(q[i] == 2) {
            cout << seg.getsum(t2[idx2], t2[idx2]+1) << endl;
            idx2++;
        }
        if(q[i] == 3) {
            seg.add(l3[idx3], r3[idx3]+1, 1);
            mp[x3[idx3]].push_back({l3[idx3], r3[idx3]});
            idx3++;
        }
    }
    return 0;
}
0