#include #include #include #include using namespace std; struct BIT{ vector bit;int size; BIT(int n){ size=n;bit=vector(n+1); } //a[i]=x void add(int i,int x){ i+=1; while(i<=size)bit[i]+=x,i+=i&-i; } //a[k] (k0)s+=bit[i],i-=i&-i; return s; } }; inline int calc_score(int stars, int users) { return 50 * stars + (500 * stars) / (8 + 2 * (users + 1)); } int main() { int N, T; cin >> N; vector L(N); for(int i = 0; i < N; i++) cin >> L[i]; cin >> T; vector names; unordered_map name_to_id; vector id, query; for(int i = 0; i < T; i++) { string name, P; cin >> name >> P; if(!name_to_id.count(name)) { name_to_id[name] = names.size(); names.push_back(name); } id.push_back(name_to_id[name]); query.push_back(P == "?" ? -1 : P[0] - 'A'); } vector score(names.size()); vector scores(1); vector solved(N); for(int i = 0; i < T; i++) { if(query[i] == -1) continue; score[id[i]] = (score[id[i]] / T + calc_score(L[query[i]], solved[query[i]])) * T + T - i - 1; scores.push_back(score[id[i]]); solved[query[i]]++; } std::sort(scores.begin(), scores.end()); BIT bit(scores.size()); solved = vector(N); score = vector(names.size()); for(int i = 0; i < T; i++) { if(query[i] == -1) { int lid = lower_bound(scores.begin(), scores.end(), score[id[i]]) - scores.begin(); cout << bit.sum(scores.size()) - bit.sum(lid + 1) + 1 << endl; continue; } bit.add(lower_bound(scores.begin(), scores.end(), score[id[i]]) - scores.begin(), -1); score[id[i]] = (score[id[i]] / T + calc_score(L[query[i]], solved[query[i]])) * T + T - i - 1; bit.add(lower_bound(scores.begin(), scores.end(), score[id[i]]) - scores.begin(), 1); solved[query[i]]++; } }