#include using namespace std; #define MAX 1007 int L[MAX]; int n; int cnt[MAX]; int gt(int id){ cnt[id]++; int val = 50 * L[id]; val += floor(50.0 * (double)L[id] / (0.8 + 0.2*(double)(cnt[id]))); return val; } vector > v; char buf[500]; map > mp; map pat; struct BIT{ vector bit; void resize(int N){ bit.assign(N+5, 0); } void add(int i, long double j){ i++; while (i < bit.size()){ bit[i] += j; i += i&-i; } } long double sum(int i){ long double r = 0; i++; while (i){ r += bit[i]; i -= i&-i; } return r; } }; map cnt2; map mp2; map las_id; map las_att; vector gain; BIT bit; map MM; map CNT; int main(){ cin >> n; for (int i = 0; i < n; i++){ cin >> L[i]; } int t; scanf("%d", &t); for (int i = 0; i < t; i++){ scanf("%s", buf); string nam = buf; scanf("%s", buf); string nn = buf; v.push_back(make_pair(nam, nn)); if (pat.count(nam)){ } else{ pat[nam] = 0; } if (nn[0] == '?'){ gain.push_back(0); continue; } pat[nam] += gt(nn[0] - 'A'); mp[pat[nam]].push_back(nam); gain.push_back(pat[nam]); } int ii = 0; for (auto it = mp.begin(); it != mp.end(); it++){ mp2[(*it).first].resize((*it).second.size() + 1); MM[(*it).first] = ii; ii++; } bit.resize(MM.size()); for (int i = 0; i < t; i++){ if (v[i].second[0] == '?'){ int SUM = mp2[las_id[v[i].first]].sum(las_att[v[i].first]); SUM += bit.sum(MM.size()-1); SUM -= bit.sum(MM[las_id[v[i].first]]); printf("%d\n", SUM); } else{ if (las_id.count(v[i].first)){ mp2[las_id[v[i].first]].add(las_att[v[i].first], -1); bit.add(MM[las_id[v[i].first]], -1); } gt(v[i].second[0]-'A'); CNT[gain[i]]++; int cc = CNT[gain[i]]; las_id[v[i].first] = gain[i]; las_att[v[i].first] = cc-1; bit.add(MM[las_id[v[i].first]], 1); mp2[gain[i]].add(cc - 1, 1); } } return 0; }