#include #include #include #include #include #include #include #include #include #include #include #include #include #include std::random_device rnd; std::mt19937 mt(rnd()); std::mt19937_64 mt_ll(rnd()); int randint(const int l, const int r){ return mt()%(r - l) + l; } long long randll(const long long l, const long long r){ return mt_ll()%(r - l) + l; } #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } int maxn; ll hilbertorder(int x, int y) { ll rx, ry, d = 0; for (ll s=maxn>>1; s; s>>=1) { rx = (x & s)>0, ry = (y & s)>0; d += s * s * ((rx * 3) ^ ry); if (ry) continue; if (rx) { x = maxn-1 - x; y = maxn-1 - y; } swap(x, y); } return d; } template class Mo{ public: vector l, r; int bucket_size; Mo(int bucket_size): l(vector()), r(vector()), bucket_size(bucket_size) {} void add_query(int l_, int r_){ l.push_back(l_); r.push_back(r_); } template vector solve(ADD_L add_left, ADD_R add_right, DEL_L del_left, DEL_R del_right, GET_ANS get_ans){ int sz = l.size(); vector ord(sz); int q = l.size(); vector eval(q); for(int i = 0; i < q; i++) eval[i] = hilbertorder(l[i], r[i]); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](const int a, const int b){ return eval[a] < eval[b]; }); int li = 0, ri = 0; vector ans(sz); for(const int i : ord){ while(li > l[i]) add_left(--li); while(ri < r[i]) add_right(ri++); while(li < l[i]) del_left(li++); while(ri > r[i]) del_right(--ri); ans[i] = get_ans(); } return ans; } }; const int N = 200000; using P = pair; deque

dq[N]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, m, q; cin >> n >> m >> q; maxn = 1; while(maxn < n ) maxn <<= 1; vector p(n); vector s(n); for(int i = 0; i < n; i++){ int pp; cin >> pp; pp--; string ss; cin >> ss; p[i] = pp; s[i] = ss == "AC"; } int ac = 0, penalty = 0; auto get_current_ac = [&](int idx){ if(dq[idx].empty()) return 0; if(dq[idx].size() >= 2) return 1; return dq[idx][0].first ? 1 : 0; }; auto get_current_penalty = [&](int idx){ if(get_current_ac(idx) == 0) return 0; if(dq[idx].empty()) return 0; if(dq[idx][0].first) return 0; return dq[idx][0].second; }; auto subtract_current = [&](int idx){ ac -= get_current_ac(idx); penalty -= get_current_penalty(idx); }; auto add_current = [&](int idx){ ac += get_current_ac(idx); penalty += get_current_penalty(idx); }; auto add_left = [&](int i){ subtract_current(p[i]); if(dq[p[i]].empty()){ dq[p[i]].push_front({s[i], 1}); }else{ auto [f, cnt] = dq[p[i]].front(); if(f == s[i]){ dq[p[i]].front().second++; }else{ dq[p[i]].push_front({s[i], 1}); } } add_current(p[i]); }; auto add_right = [&](int i){ subtract_current(p[i]); if(dq[p[i]].empty()){ dq[p[i]].push_back({s[i], 1}); }else{ auto [f, cnt] = dq[p[i]].back(); if(f == s[i]){ dq[p[i]].back().second++; }else{ dq[p[i]].push_back({s[i], 1}); } } add_current(p[i]); }; auto del_left = [&](int i){ subtract_current(p[i]); dq[p[i]].front().second--; if(dq[p[i]].front().second == 0) dq[p[i]].pop_front(); add_current(p[i]); }; auto del_right = [&](int i){ subtract_current(p[i]); dq[p[i]].back().second--; if(dq[p[i]].back().second == 0) dq[p[i]].pop_back(); add_current(p[i]); }; auto get_ans = [&](){ return make_pair(ac, penalty); }; int sq = sqrt(n); auto mo = Mo>(sq); for(int i = 0; i < q; i++){ int l, r; cin >> l >> r; l--; mo.add_query(l, r); } auto ans = mo.solve(add_left, add_right, del_left, del_right, get_ans); for(auto [a, p]: ans){ cout << a << ' ' << p << '\n'; } }