結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー pekempeypekempey
提出日時 2016-11-19 02:24:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 216 ms / 5,000 ms
コード長 2,948 bytes
コンパイル時間 1,962 ms
コンパイル使用メモリ 183,140 KB
実行使用メモリ 18,736 KB
最終ジャッジ日時 2023-10-23 15:50:48
合計ジャッジ時間 11,007 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 164 ms
6,936 KB
testcase_13 AC 182 ms
9,740 KB
testcase_14 AC 197 ms
8,560 KB
testcase_15 AC 171 ms
10,304 KB
testcase_16 AC 185 ms
9,124 KB
testcase_17 AC 187 ms
9,140 KB
testcase_18 AC 216 ms
6,924 KB
testcase_19 AC 195 ms
8,556 KB
testcase_20 AC 193 ms
8,536 KB
testcase_21 AC 177 ms
9,716 KB
testcase_22 AC 177 ms
9,748 KB
testcase_23 AC 162 ms
6,928 KB
testcase_24 AC 183 ms
9,132 KB
testcase_25 AC 178 ms
6,016 KB
testcase_26 AC 190 ms
5,096 KB
testcase_27 AC 177 ms
9,716 KB
testcase_28 AC 175 ms
9,728 KB
testcase_29 AC 193 ms
8,520 KB
testcase_30 AC 168 ms
10,320 KB
testcase_31 AC 180 ms
9,744 KB
testcase_32 AC 195 ms
8,548 KB
testcase_33 AC 186 ms
9,152 KB
testcase_34 AC 187 ms
6,028 KB
testcase_35 AC 168 ms
10,340 KB
testcase_36 AC 183 ms
6,020 KB
testcase_37 AC 165 ms
18,736 KB
testcase_38 AC 196 ms
11,188 KB
testcase_39 AC 179 ms
11,188 KB
testcase_40 AC 184 ms
11,188 KB
testcase_41 AC 143 ms
13,564 KB
testcase_42 AC 143 ms
13,564 KB
testcase_43 AC 169 ms
6,372 KB
testcase_44 AC 131 ms
8,416 KB
testcase_45 AC 166 ms
18,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

// left-leaning red-black tree
template<class TKey>
class Set {
public:
    void insert(TKey key) {
        root = insert(root, create(key));
        root->c = false;
    }

    void erase(TKey key) {
        root = erase(root, key);
    }

    int index_of(TKey key) {
        return index_of(root, key);
    }

private:
    struct node {
        node *l;
        node *r;
        bool c = 0;
        int sz = 0;
        TKey key;
        bool removed = false;
    };

    node *nil = new node();
    node *root = nil;

    node *create(TKey key) {
        node *res = new node();
        res->l = res->r = nil;
        res->c = true;
        res->sz = 1;
        res->key = key;
        return res;
    }

    node *fix(node *x) {
        if (x == nil) return x;
        x->sz = !x->removed + x->l->sz + x->r->sz;
        return x;
    }

    node *rotL(node *x) {
        node *y = x->r;
        node *t = y->l;
        y->l = x;
        x->r = t;
        y->c = x->c;
        x->c = true;
        fix(x);
        return fix(y);
    }

    node *rotR(node *x) {
        node *y = x->l;
        node *t = y->r;
        y->r = x;
        x->l = t;
        y->l->c = false;
        x->c = false;
        y->c = true;
        fix(x);
        return fix(y);
    }

    node *insert(node *x, node *y) {
        if (x == nil) return y;
        if (y->key < x->key) {
            x->l = insert(x->l, y);
        } else {
            x->r = insert(x->r, y);
        }
        fix(x);
        if (x->r->c) x = rotL(x);
        if (x->l->c && x->l->l->c) x = rotR(x);
        return x;
    }

    node *erase(node *x, TKey key) {
        if (!x->removed && x->key == key) {
            x->removed = true;
            return fix(x);
        }
        if (key < x->key) {
            x->l = erase(x->l, key);
        } else {
            x->r = erase(x->r, key);
        }
        return fix(x);
    }

    int index_of(node *x, TKey key) {
        if (x->key == key) return x->l->sz;
        if (key < x->key) {
            return index_of(x->l, key);
        } else {
            return x->l->sz + !x->removed + index_of(x->r, key);
        }
    }
};

int main() {
    int n, T;
    cin >> n;
    vector<int> L(n);
    for (int i = 0; i < n; i++) scanf("%d", &L[i]);
    cin >> T;
    unordered_map<string, pair<int, int>> score;
    Set<pair<int, int>> st;
    vector<int> cnt(n);
    for (int ii = 0; ii < T; ii++) {
        string name, prob;
        cin >> name >> prob;
        int s, t;
        tie(s, t) = score[name];
        if (prob[0] == '?') {
            printf("%d\n", score.size() - st.index_of(score[name]));
        } else {
            int id = prob[0] - 'A';
            cnt[id]++;
            int ss = s + 50 * L[id] + 500 * L[id] / (8 + 2 * cnt[id]);
            if (s > 0) st.erase({ s, t });
            st.insert({ ss, -ii });
            score[name] = { ss, -ii };
        }
    }
}
0