#include using namespace std; using ll = long long; #define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i) #define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i) #define all(x) begin(x), end(x) template bool chmax(T& a, const T& b) { return a < b ? (a = b, 1) : 0; } template bool chmin(T& a, const T& b) { return a > b ? (a = b, 1) : 0; } class Mo { public: Mo() = default; explicit Mo(int n) : n(n), cnt(0) {} void query(int l, int r) { queries.emplace_back(cnt++, l, r); } template void run(ExL exl, ShL shl, ExR exr, ShR shr, Out out) { int nbucket = std::max(1, (int)std::sqrt(queries.size())); int s = (n + nbucket - 1) / nbucket; std::sort(queries.begin(), queries.end(), [&](const auto& a, const auto& b) { if (a.l / s != b.l / s) return a.l < b.l; return a.r < b.r; }); int curL = 0, curR = 0; for (auto [id, l, r] : queries) { while (curL > l) exl(--curL); while (curR < r) exr(curR++); while (curL < l) shl(curL++); while (curR > r) shr(--curR); out(id); } } private: struct Query { int id, l, r; Query(int id, int l, int r) : id(id), l(l), r(r) {} }; int n, cnt; std::vector queries; }; template ostream& operator<<(ostream& os, const vector& v) { for (int i = 0; i < (int)v.size(); ++i) { os << v[i]; if (i < (int)v.size() - 1) os << " "; } return os; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int N, M, Q; cin >> N >> M >> Q; vector P(N); vector ac(N); rep(i, 0, N) { int p; string s; cin >> p >> s; --p; P[i] = p; ac[i] = s == "AC"; } Mo mo(N); vector ans_correct(Q), ans_penalty(Q); rep(_, 0, Q) { int l, r; cin >> l >> r; --l; mo.query(l, r); } vector>> sub(M); vector ac_cnt(M), penalty(M); int cur_correct = 0, cur_penalty = 0; auto exl = [&](int i) { int p = P[i]; if (ac_cnt[p]) --cur_correct; cur_penalty -= penalty[p]; if (!sub[p].empty() && sub[p].front().first == ac[i]) { sub[p].front().second++; } else { sub[p].push_front({ac[i], 1}); } if (ac[i]) ++ac_cnt[p]; if (ac_cnt[p] && !sub[p].front().first) { penalty[p] = sub[p].front().second; } else { penalty[p] = 0; } if (ac_cnt[p]) ++cur_correct; cur_penalty += penalty[p]; }; auto shl = [&](int i) { int p = P[i]; if (ac_cnt[p]) --cur_correct; cur_penalty -= penalty[p]; sub[p].front().second--; if (sub[p].front().second == 0) sub[p].pop_front(); if (ac[i]) --ac_cnt[p]; if (ac_cnt[p] && !sub[p].front().first) { penalty[p] = sub[p].front().second; } else { penalty[p] = 0; } if (ac_cnt[p]) ++cur_correct; cur_penalty += penalty[p]; }; auto exr = [&](int i) { int p = P[i]; if (ac_cnt[p]) --cur_correct; cur_penalty -= penalty[p]; if (!sub[p].empty() && sub[p].back().first == ac[i]) { sub[p].back().second++; } else { sub[p].push_back({ac[i], 1}); } if (ac[i]) ++ac_cnt[p]; if (ac_cnt[p] && !sub[p].front().first) { penalty[p] = sub[p].front().second; } else { penalty[p] = 0; } if (ac_cnt[p]) ++cur_correct; cur_penalty += penalty[p]; }; auto shr = [&](int i) { int p = P[i]; if (ac_cnt[p]) --cur_correct; cur_penalty -= penalty[p]; sub[p].back().second--; if (sub[p].back().second == 0) sub[p].pop_back(); if (ac[i]) --ac_cnt[p]; if (ac_cnt[p] && !sub[p].front().first) { penalty[p] = sub[p].front().second; } else { penalty[p] = 0; } if (ac_cnt[p]) ++cur_correct; cur_penalty += penalty[p]; }; auto out = [&](int id) { ans_correct[id] = cur_correct; ans_penalty[id] = cur_penalty; }; mo.run(exl, shl, exr, shr, out); rep(i, 0, Q) { cout << ans_correct[i] << " " << ans_penalty[i] << "\n"; } }