結果
| 問題 |
No.449 ゆきこーだーの雨と雪 (4)
|
| ユーザー |
|
| 提出日時 | 2016-11-19 03:06:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
#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 };
}
}
}