結果

問題 No.2421 entersys?
ユーザー t98slidert98slider
提出日時 2023-08-12 14:32:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,205 bytes
コンパイル時間 2,601 ms
コンパイル使用メモリ 211,680 KB
実行使用メモリ 37,448 KB
最終ジャッジ日時 2024-04-30 06:24:32
合計ジャッジ時間 10,736 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 366 ms
29,188 KB
testcase_12 AC 355 ms
29,080 KB
testcase_13 AC 365 ms
29,292 KB
testcase_14 AC 361 ms
29,128 KB
testcase_15 AC 372 ms
29,248 KB
testcase_16 AC 371 ms
31,616 KB
testcase_17 AC 358 ms
31,520 KB
testcase_18 AC 361 ms
31,528 KB
testcase_19 AC 371 ms
31,584 KB
testcase_20 AC 372 ms
32,108 KB
testcase_21 AC 355 ms
30,956 KB
testcase_22 AC 272 ms
26,168 KB
testcase_23 AC 462 ms
37,360 KB
testcase_24 AC 464 ms
37,264 KB
testcase_25 AC 462 ms
37,448 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template <class T> struct fenwick_tree {
    using U = T;

    public:
    fenwick_tree() : _n(0) {}
    fenwick_tree(int n) : _n(n), data(n) {}

    void add(int p, T x) {
        assert(0 <= p && p < _n);
        p++;
        while (p <= _n) {
            data[p - 1] += U(x);
            p += p & -p;
        }
    }

    T sum(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        return sum(r) - sum(l);
    }

    private:
    int _n;
    std::vector<U> data;

    U sum(int r) {
        U s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<tuple<string, int, int>> a(n);
    vector<string> ca(n);
    vector<int> ct(2 * n);
    for(int i = 0; i < n; i++){
        string s;
        int l, r;
        cin >> s >> l >> r;
        a[i] = make_tuple(s, l, r + 1);
        ca[i] = s;
        ct[i] = l;
        ct[i + n] = r + 1;
    }
    int Q;
    cin >> Q;
    vector<tuple<int, string, int, int>> query(Q);
    for(int i = 0; i < Q; i++){
        string s;
        int cmd, l, r, x;
        cin >> cmd;
        if(cmd == 1){
            cin >> s >> x;
            ca.push_back(s);
            query[i] = make_tuple(cmd, s, x, 0);
            ct.push_back(x);
        }else if(cmd == 2){
            cin >> x;
            query[i] = make_tuple(cmd, "", x, 0);
            ct.push_back(x);
        }else if(cmd == 3){
            cin >> s >> l >> r;
            query[i] = make_tuple(cmd, s, l, r + 1);
            ca.push_back(s);
            ct.push_back(l);
            ct.push_back(r + 1);
        }
    }
    sort(ca.begin(), ca.end());
    ca.erase(unique(ca.begin(), ca.end()), ca.end());
    ct.push_back(0);
    sort(ct.begin(), ct.end());
    ct.erase(unique(ct.begin(), ct.end()), ct.end());

    fenwick_tree<int> fw(ct.size() + 1);
    vector<set<pair<int,int>>> S(ca.size());
    for(int i = 0; i < ca.size(); i++) S[i].insert({1 << 30, 1 << 30});
    auto add = [&](string s, int l, int r){
        int id = lower_bound(ca.begin(), ca.end(), s) - ca.begin();
        S[id].insert({r, l});
        l = lower_bound(ct.begin(), ct.end(), l) - ct.begin();
        r = lower_bound(ct.begin(), ct.end(), r) - ct.begin();
        fw.add(l, 1);
        fw.add(r, -1);
    };
    auto search = [&](string s, int t){
        int id = lower_bound(ca.begin(), ca.end(), s) - ca.begin();
        auto it = S[id].lower_bound({t, -1});
        if(it->second <= t && t <= it->first) return true;
        return false;
    };

    for(int i = 0; i < n; i++){
        string s;
        int l, r;
        tie(s, l, r) = a[i];
        add(s, l, r);
    }

    for(int i = 0; i < Q; i++){
        string s;
        int cmd, l, r;
        tie(cmd, s, l, r) = query[i];
        if(cmd == 1){
            cout << (search(s, l) ? "Yes" : "No") << '\n';
        }else if(cmd == 2){
            int t = lower_bound(ct.begin(), ct.end(), l) - ct.begin();
            cout << fw.sum(0, t + 1) << '\n';
        }else{
            add(s, l, r);
        }
    }
}
0