結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー pekempeypekempey
提出日時 2016-11-19 02:34:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 171 ms / 5,000 ms
コード長 3,011 bytes
コンパイル時間 4,065 ms
コンパイル使用メモリ 183,548 KB
実行使用メモリ 17,348 KB
最終ジャッジ日時 2023-10-23 15:49:58
合計ジャッジ時間 8,130 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,964 KB
testcase_01 AC 5 ms
6,964 KB
testcase_02 AC 5 ms
6,960 KB
testcase_03 AC 6 ms
6,980 KB
testcase_04 AC 5 ms
6,980 KB
testcase_05 AC 4 ms
6,980 KB
testcase_06 AC 4 ms
6,980 KB
testcase_07 AC 4 ms
6,980 KB
testcase_08 AC 5 ms
6,980 KB
testcase_09 AC 5 ms
6,980 KB
testcase_10 AC 5 ms
6,980 KB
testcase_11 AC 5 ms
6,980 KB
testcase_12 AC 82 ms
7,200 KB
testcase_13 AC 171 ms
9,484 KB
testcase_14 AC 97 ms
9,364 KB
testcase_15 AC 143 ms
9,364 KB
testcase_16 AC 107 ms
9,356 KB
testcase_17 AC 111 ms
9,488 KB
testcase_18 AC 82 ms
7,196 KB
testcase_19 AC 107 ms
9,364 KB
testcase_20 AC 101 ms
9,352 KB
testcase_21 AC 124 ms
9,360 KB
testcase_22 AC 116 ms
9,488 KB
testcase_23 AC 78 ms
7,196 KB
testcase_24 AC 107 ms
9,360 KB
testcase_25 AC 74 ms
7,200 KB
testcase_26 AC 66 ms
7,200 KB
testcase_27 AC 132 ms
9,364 KB
testcase_28 AC 116 ms
9,488 KB
testcase_29 AC 102 ms
9,352 KB
testcase_30 AC 156 ms
9,364 KB
testcase_31 AC 122 ms
9,488 KB
testcase_32 AC 129 ms
9,360 KB
testcase_33 AC 114 ms
9,488 KB
testcase_34 AC 77 ms
7,200 KB
testcase_35 AC 134 ms
9,488 KB
testcase_36 AC 70 ms
7,200 KB
testcase_37 AC 139 ms
17,348 KB
testcase_38 AC 98 ms
11,820 KB
testcase_39 AC 86 ms
11,820 KB
testcase_40 AC 78 ms
11,820 KB
testcase_41 AC 106 ms
11,820 KB
testcase_42 AC 105 ms
11,820 KB
testcase_43 AC 65 ms
7,164 KB
testcase_44 AC 76 ms
7,328 KB
testcase_45 AC 131 ms
17,348 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;
        bool removed = false;
        int sz = 0;
        TKey key;
    };

    int ptr = 0;
    node pool[101010];

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

    node *create(TKey key) {
        node *res = &pool[ptr++];
        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), cnt(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;
    for (int ii = 0; ii < T; ii++) {
        char buf[17], prob[2];
        scanf("%s %s", buf, prob);
        string name(buf);
        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