#include using namespace std; using ll=int; using pll=pair; using tll=tuple; using ld=long double; //const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define all(v) v.begin(),v.end() #include #include using namespace __gnu_pbds; template void chmin(T &a,T b){ if(a>b){ a=b; } } template void chmax(T &a,T b){ if(a> lr; Mo(int x){ n=x; } void add(int l,int r){ lr.emplace_back(l,r); } template void solve(IL &insert_left,IR &insert_right,EL &erase_left,ER &erase_right,O &output){ int q=lr.size(); if(q==0) return; int block_size=max(1,n/(int)sqrt(q)); vector ord(q); for(int i=0;ilr[j].second; else return lr[i].second void solve(I &insert,E &erase,O &output){ solve(insert,insert,erase,erase,output); } }; ll f(deque &d,ll x){ ll n=d.size(); if(n==0) return 0; if(x> n >> m >> q; vector p(n); vector s(n); rep(i,n){ cin >> p[i]; p[i]--; string str; cin >> str; if(str=="AC") s[i]=true; if(str=="WA") s[i]=false; } Mo mo(n); vector ac(q),wa(q); rep(i,q){ ll l,r; cin >> l >> r; l--; mo.add(l,r); } vector> a(m),w(m); ll now_a=0,now_w=0; auto il=[&](ll i){ if(s[i]){ if((ll)a[p[i]].size()==0) now_a++; else now_w-=f(w[p[i]],a[p[i]].front()); a[p[i]].push_front(i); }else{ if(1<=(ll)a[p[i]].size()) now_w++; w[p[i]].push_front(i); } }; auto ir=[&](ll i){ if(s[i]){ if((ll)a[p[i]].size()==0){ now_a++; now_w+=f(w[p[i]],i); } a[p[i]].push_back(i); }else{ w[p[i]].push_back(i); } }; auto el=[&](ll i){ if(s[i]){ a[p[i]].pop_front(); if((ll)a[p[i]].size()==0){ now_a--; }else{ now_w-=f(w[p[i]],i); now_w+=f(w[p[i]],a[p[i]].front()); } }else{ w[p[i]].pop_front(); if(1<=(ll)a[p[i]].size()) now_w--; } }; auto er=[&](ll i){ if(s[i]){ a[p[i]].pop_back(); if((ll)a[p[i]].size()==0){ now_a--; now_w-=f(w[p[i]],i); } }else{ w[p[i]].pop_back(); } }; auto o=[&](ll i){ ac[i]=now_a; wa[i]=now_w; }; mo.solve(il,ir,el,er,o); rep(i,q){ cout << ac[i] << " " << wa[i] << '\n'; } }