結果
問題 | No.449 ゆきこーだーの雨と雪 (4) |
ユーザー | pekempey |
提出日時 | 2016-11-19 03:06:27 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 77 ms / 5,000 ms |
コード長 | 4,414 bytes |
コンパイル時間 | 3,604 ms |
コンパイル使用メモリ | 204,864 KB |
実行使用メモリ | 11,992 KB |
最終ジャッジ日時 | 2024-09-22 10:22:04 |
合計ジャッジ時間 | 7,437 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,912 KB |
testcase_01 | AC | 4 ms
6,816 KB |
testcase_02 | AC | 4 ms
6,940 KB |
testcase_03 | AC | 3 ms
6,944 KB |
testcase_04 | AC | 4 ms
6,940 KB |
testcase_05 | AC | 4 ms
6,940 KB |
testcase_06 | AC | 4 ms
6,940 KB |
testcase_07 | AC | 4 ms
6,940 KB |
testcase_08 | AC | 4 ms
6,944 KB |
testcase_09 | AC | 4 ms
6,944 KB |
testcase_10 | AC | 4 ms
6,940 KB |
testcase_11 | AC | 4 ms
6,940 KB |
testcase_12 | AC | 57 ms
7,432 KB |
testcase_13 | AC | 71 ms
9,088 KB |
testcase_14 | AC | 60 ms
9,088 KB |
testcase_15 | AC | 76 ms
8,832 KB |
testcase_16 | AC | 65 ms
8,988 KB |
testcase_17 | AC | 67 ms
8,880 KB |
testcase_18 | AC | 57 ms
7,424 KB |
testcase_19 | AC | 58 ms
8,832 KB |
testcase_20 | AC | 60 ms
8,832 KB |
testcase_21 | AC | 71 ms
8,960 KB |
testcase_22 | AC | 74 ms
8,960 KB |
testcase_23 | AC | 58 ms
7,296 KB |
testcase_24 | AC | 70 ms
8,960 KB |
testcase_25 | AC | 50 ms
7,296 KB |
testcase_26 | AC | 40 ms
7,296 KB |
testcase_27 | AC | 74 ms
8,832 KB |
testcase_28 | AC | 73 ms
9,020 KB |
testcase_29 | AC | 54 ms
8,860 KB |
testcase_30 | AC | 77 ms
9,028 KB |
testcase_31 | AC | 73 ms
8,896 KB |
testcase_32 | AC | 57 ms
8,960 KB |
testcase_33 | AC | 63 ms
8,924 KB |
testcase_34 | AC | 49 ms
7,500 KB |
testcase_35 | AC | 76 ms
8,884 KB |
testcase_36 | AC | 49 ms
7,464 KB |
testcase_37 | AC | 66 ms
11,992 KB |
testcase_38 | AC | 47 ms
9,656 KB |
testcase_39 | AC | 44 ms
9,728 KB |
testcase_40 | AC | 45 ms
9,544 KB |
testcase_41 | AC | 60 ms
9,620 KB |
testcase_42 | AC | 62 ms
9,728 KB |
testcase_43 | AC | 43 ms
7,424 KB |
testcase_44 | AC | 52 ms
7,424 KB |
testcase_45 | AC | 52 ms
11,976 KB |
ソースコード
#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'); } pair<uint64_t, uint64_t> summary(string s) { uint64_t x = 0, y = 0; for (int i = 0; i < 8; i++) x = x * 27 + (i < s.size() ? s[i] - 'a' : 26); for (int i = 8; i < 16; i++) y = y * 27 + (i < s.size() ? s[i] - 'a' : 26); return{ x, y }; } int rnd; namespace std { template <> class hash<std::pair<uint64_t, uint64_t>> { public: size_t operator()(const std::pair<uint64_t, uint64_t> &x) const { return hash<int>()(x.first & UINT_MAX) ^ hash<int>()(x.second & UINT_MAX) ^ hash<int>()(x.first >> 32 & UINT_MAX) ^ hash<int>()(x.second >> 32 & UINT_MAX) ^ rnd; } }; } int main() { srand(time(NULL)); rnd = rand() << 16 ^ rand(); 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<pair<uint64_t, uint64_t>, pair<int, int>> score; score.reserve(T + 100); Set<pair<int, int>> st; for (int ii = 0; ii < T; ii++) { auto name = summary(read_string()); char prob = read_string()[0]; int s, t; tie(s, t) = score[name]; 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 }); score[name] = { ss, -ii }; } } }