結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー pekempeypekempey
提出日時 2016-11-19 02:22:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,947 bytes
コンパイル時間 1,886 ms
コンパイル使用メモリ 183,096 KB
実行使用メモリ 10,740 KB
最終ジャッジ日時 2023-10-23 15:48:36
合計ジャッジ時間 9,418 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 4 ms
4,348 KB
testcase_04 AC 4 ms
4,348 KB
testcase_05 AC 5 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = true;
        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