結果

問題 No.449 ゆきこーだーの雨と雪 (4)
ユーザー pekempeypekempey
提出日時 2016-11-19 03:08:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 5,000 ms
コード長 3,726 bytes
コンパイル時間 3,464 ms
コンパイル使用メモリ 202,864 KB
実行使用メモリ 16,752 KB
最終ジャッジ日時 2023-10-23 15:51:50
合計ジャッジ時間 7,055 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,856 KB
testcase_01 AC 4 ms
6,856 KB
testcase_02 AC 4 ms
6,856 KB
testcase_03 AC 4 ms
6,876 KB
testcase_04 AC 4 ms
6,876 KB
testcase_05 AC 5 ms
6,876 KB
testcase_06 AC 4 ms
6,872 KB
testcase_07 AC 4 ms
6,876 KB
testcase_08 AC 5 ms
6,872 KB
testcase_09 AC 4 ms
6,876 KB
testcase_10 AC 4 ms
6,872 KB
testcase_11 AC 4 ms
6,872 KB
testcase_12 AC 60 ms
7,512 KB
testcase_13 AC 65 ms
9,624 KB
testcase_14 AC 58 ms
9,624 KB
testcase_15 AC 72 ms
9,624 KB
testcase_16 AC 62 ms
9,624 KB
testcase_17 AC 62 ms
9,624 KB
testcase_18 AC 67 ms
7,512 KB
testcase_19 AC 59 ms
9,624 KB
testcase_20 AC 56 ms
9,624 KB
testcase_21 AC 79 ms
9,624 KB
testcase_22 AC 67 ms
9,624 KB
testcase_23 AC 58 ms
7,512 KB
testcase_24 AC 60 ms
9,624 KB
testcase_25 AC 51 ms
7,512 KB
testcase_26 AC 43 ms
7,512 KB
testcase_27 AC 65 ms
9,624 KB
testcase_28 AC 68 ms
9,624 KB
testcase_29 AC 55 ms
9,624 KB
testcase_30 AC 71 ms
9,624 KB
testcase_31 AC 69 ms
9,624 KB
testcase_32 AC 56 ms
9,624 KB
testcase_33 AC 62 ms
9,624 KB
testcase_34 AC 52 ms
7,512 KB
testcase_35 AC 74 ms
9,624 KB
testcase_36 AC 52 ms
7,512 KB
testcase_37 AC 70 ms
16,752 KB
testcase_38 AC 51 ms
12,000 KB
testcase_39 AC 46 ms
12,000 KB
testcase_40 AC 47 ms
12,000 KB
testcase_41 AC 61 ms
12,000 KB
testcase_42 AC 62 ms
12,000 KB
testcase_43 AC 44 ms
7,512 KB
testcase_44 AC 52 ms
7,512 KB
testcase_45 AC 70 ms
16,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
#define getchar getchar_unlocked
#define putchar putchar_unlocked
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 read_int() {
    int n, c;
    while ((c = getchar()) < '0') if (c == EOF) abort();
    n = c - '0';
    while ((c = getchar()) >= '0') n = n * 10 + c - '0';
    return n;
}

string read_string() {
    char buf[256];
    int c, len = 0;
    while ((c = getchar()) < '!') if (c == EOF) abort();
    buf[len++] = c;
    while ((c = getchar()) >= '!') buf[len++] = c;
    buf[len] = '\0';
    return string(buf);
}

void put_int(int n) {
    int res[11], i = 0;
    do { res[i++] = n % 10, n /= 10; } while (n);
    while (i) putchar(res[--i] + '0');
    putchar('\n');
}

int main() {
    int n = read_int();
    vector<int> L(n), cnt(n);
    for (int i = 0; i < n; i++) L[i] = read_int();
    int T = read_int();
    unordered_map<string, pair<int, int>> score;
    score.reserve(T + 100);
    Set<pair<int, int>> st;
    for (int ii = 0; ii < T; ii++) {
        string name = read_string();
        char prob = read_string()[0];
        int s, t;
        auto &tmp = score[name];
        tie(s, t) = tmp;
        if (prob == '?') {
            put_int(score.size() - st.index_of(score[name]));
        } else {
            int id = prob - '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 });
            tmp = { ss, -ii };
        }
    }
}
0