#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; } // https://take44444.github.io/Algorithm-Book/range/mo/main.html 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; const int inf = 1e9; 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> idx(m); vector p(n); vector ord(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"; ord[i] = idx[p[i]].size(); idx[p[i]].push_back(i); } vector> next_ac(m); for(int i = 0; i < m; i++){ next_ac[i].resize(idx[i].size()+1); int last = inf; next_ac[i][idx[i].size()] = inf; for(int j = idx[i].size()-1; j >= 0; j--){ int ii = idx[i][j]; if(s[ii]) { last = j; } next_ac[i][j] = last; } } vector l_pos(m), r_pos(m); int ac = 0, penalty = 0; auto get_current_ac = [&](int pp){ if(next_ac[pp][l_pos[pp]] < r_pos[pp]) return 1; return 0; }; auto get_current_penalty = [&](int pp){ if(get_current_ac(pp) == 0) return 0; return next_ac[pp][l_pos[pp]]-l_pos[pp]; }; 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]); l_pos[p[i]]--; add_current(p[i]); }; auto add_right = [&](int i){ subtract_current(p[i]); r_pos[p[i]]++; add_current(p[i]); }; auto del_left = [&](int i){ subtract_current(p[i]); l_pos[p[i]]++; add_current(p[i]); }; auto del_right = [&](int i){ subtract_current(p[i]); r_pos[p[i]]--; 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'; } }