#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 multisetRBST{ private: unsigned xor128() { static unsigned x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned t = x ^ (x << 11); x = y; y = z; z = w; return w = w ^ (w >> 19) ^ (t ^ (t >> 8)); } struct Node{ Node *l,*r; size_t cnt; T val; Node():cnt(0){l=r=nullptr;} Node(T val): cnt(1),val(val){l=r=nullptr;} }; const size_t LIM = 1e6; vector pool; size_t ptr; Node *root; T id; inline Node* create(){ return &pool[ptr++]; } inline Node* create(T v){ return &(pool[ptr++]=Node(v)); } inline size_t size(const Node* a){ if(a==nullptr) return 0; return a->cnt; } inline Node* update(Node* a){ if(a==nullptr) return a; a->cnt=size(a->l)+size(a->r)+1; return a; } Node* merge(Node* a,Node* b){ if(a==nullptr) return b; if(b==nullptr) return a; if(xor128()%(size(a)+size(b))r=merge(a->r,b); return update(a); } b->l=merge(a,b->l); return update(b); } pair split(Node* a,size_t k){ if(a==nullptr) return make_pair(a,a); if(k<=size(a->l)){ auto s=split(a->l,k); a->l=s.second; return make_pair(s.first,update(a)); } auto s=split(a->r,k-(size(a->l)+1)); a->r=s.first; return make_pair(update(a),s.second); } inline size_t lower_bound(Node *a,T v){ if(!a) return 0; if(v<=a->val)return lower_bound(a->l,v); else return size(a->l)+lower_bound(a->r,v)+1; } inline size_t upper_bound(Node *a,T v){ if(!a) return 0; if(vval)return upper_bound(a->l,v); else return size(a->l)+upper_bound(a->r,v)+1; } inline T get(Node *a,size_t k){ if(!a) return id; if(k == size(a->l)) return a->val; if(k < size(a->l)) return get(a->l,k); else return get(a->r,k-size(a->l)-1); } public: multisetRBST(T id_):pool(LIM),ptr(0),root(nullptr),id(id_){} inline void insert(T v){ Node* b=create(v); auto s=split(root,lower_bound(v)); root=merge(merge(s.first,b),s.second); } inline void erase(T v){ assert(count(v)>0); auto s=split(root,lower_bound(v)); auto t=split(s.second,1); root=merge(s.first,t.second); } inline size_t lower_bound(T v){ return lower_bound(root,v); } inline size_t upper_bound(T v){ return upper_bound(root,v); } inline size_t count(T v){ return upper_bound(v)-lower_bound(v); } inline T kth_elment(size_t k){ return get(root,k); } }; 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; multisetRBST > S({-INF,-INF}); 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],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],lastup[idx]}); } } return 0; }