#include #define debug(x) cerr << #x << ": " << x << endl #define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << endl using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector vll; const ll INF = LLONG_MAX/2; const ll MOD = 1e9+7; const double EPS=1e-12; template class BinaryTrie { struct node { int cnt; KEYTYPE lazy; node *ch[2]; node() : cnt(0), lazy(0), ch{ nullptr, nullptr } {} }; node* insert_node(node* t, KEYTYPE key, int b = B - 1) { if (!t) t = new node; t->cnt += 1; if (b < 0) return t; push(t, b); bool f = (key >> (KEYTYPE)b) & (KEYTYPE)1; t->ch[f] = insert_node(t->ch[f], key, b - 1); return t; } node* erase_node(node* t, KEYTYPE key, int b = B - 1) { assert(t); t->cnt -= 1; if (t->cnt == 0) return nullptr; if (b < 0) return t; push(t, b); bool f = (key >> (KEYTYPE)b) & (KEYTYPE)1; t->ch[f] = erase_node(t->ch[f], key, b - 1); return t; } //[ void push(node* t, int b) { if ((t->lazy >> (KEYTYPE)b) & (KEYTYPE)1) swap(t->ch[0], t->ch[1]); if (t->ch[0]) t->ch[0]->lazy ^= t->lazy; if (t->ch[1]) t->ch[1]->lazy ^= t->lazy; t->lazy = 0; } int count_lower(node* t, KEYTYPE key, int b = B - 1) { if (!t || b < 0) return 0; push(t, b); bool f = (key >> (KEYTYPE)b) & (KEYTYPE)1; return (f && t->ch[0] ? t->ch[0]->cnt : 0) + count_lower(t->ch[f], key, b - 1); } //] node *root; public: BinaryTrie() : root(nullptr) {} int size() const { return root ? root->cnt : 0; } void insert(KEYTYPE key) { root = insert_node(root, key); } void erase(KEYTYPE key) { root = erase_node(root, key); } int lower_bound(KEYTYPE key) { // return id return count_lower(root, key); } }; int id(string name){ static int cnt=0; static map mp; if(mp.count(name)==0){ mp[name]=cnt++; return cnt-1; }else{ return mp[name]; } } signed main(){ cin.tie(0); ios::sync_with_stdio(false); ll N;cin>>N; ll L[N]; for(ll i=0;i>L[i]; ll score[100010]={}; ll lastup[100010]={}; ll ac[N]={}; ll T;cin>>T; BinaryTrie<> S; for(ll t=1;t<=T;t++){ string Name;char P;cin>>Name>>P; ll idx=id(Name); if(P=='?'){ //debug(S.size()); cout<0)S.erase(score[idx]*T+T-lastup[idx]); score[idx]+=50*L[P-'A']+50*L[P-'A']*10/(8+2*++ac[P-'A']); lastup[idx]=t; S.insert(score[idx]*T+T-lastup[idx]); } } return 0; }