#include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; struct Mo { explicit Mo(const std::vector& ls, const std::vector& rs) : n(ls.size()), ptr(0), nl(0), nr(0), ls(ls), rs(rs) { const int width = std::round(std::sqrt(n)); order.resize(n); std::iota(order.begin(), order.end(), 0); std::sort(order.begin(), order.end(), [&ls, &rs, width](const int a, const int b) -> bool { if (ls[a] / width != ls[b] / width) return ls[a] < ls[b]; return (ls[a] / width) & 1 ? rs[a] < rs[b] : rs[a] > rs[b]; }); } int process() { if (ptr == n) [[unlikely]] return -1; const int id = order[ptr++]; while (ls[id] < nl) add(--nl); while (nr < rs[id]) add(nr++); while (nl < ls[id]) del(nl++); while (rs[id] < nr) del(--nr); return id; } void add(const int idx) const; void del(const int idx) const; int nl, nr; private: const int n; int ptr; std::vector ls, rs, order; }; constexpr int N = 200000, M = 200000; int p[M]{}, num[N]{}, nxt[N]{}; bool s[M]{}; int al[M]{}, ac[M]{}; int atc = 0; ll penalty = 0; void Mo::add(const int idx) const { const int prob = p[idx]; if (idx == nl) { if (s[idx]) { if (ac[prob] == 0) { ++atc; } else { penalty -= num[nxt[idx]] - num[idx] - 1; } ++ac[prob]; } else { if (ac[prob] > 0) ++penalty; } } else { if (s[idx]) { if (ac[prob] == 0) { ++atc; penalty += al[prob]; } ++ac[prob]; } } ++al[prob]; // cout << "[add] " << idx << ' ' << atc << ' ' << penalty << '\n'; } void Mo::del(const int idx) const { const int prob = p[idx]; --al[prob]; if (idx + 1 == nl) { if (s[idx]) { --ac[prob]; if (ac[prob] == 0) { --atc; } else { penalty += num[nxt[idx]] - num[idx] - 1; } } else { if (ac[prob] > 0) --penalty; } } else { if (s[idx] && --ac[prob] == 0) { --atc; penalty -= al[prob]; } } // cout << "[del] " << idx << ' ' << atc << ' ' << penalty << '\n'; } int main() { int n, m, q; cin >> n >> m >> q; REP(i, n) { string ac_or_wa; cin >> p[i] >> ac_or_wa; --p[i]; s[i] = (ac_or_wa == "AC"); } vector last(m, -1); REP(i, n) { if (last[p[i]] != -1) num[i] = num[last[p[i]]]; ++num[i]; last[p[i]] = i; } ranges::fill(last, -1); fill(nxt, nxt + n, -1); REP(i, n) { if (s[i]) { if (last[p[i]] != -1) nxt[last[p[i]]] = i; last[p[i]] = i; } } vector l(q), r(q); REP(i, q) cin >> l[i] >> r[i], --l[i]; Mo mo(l, r); vector ans1(q); vector ans2(q); REP(_, q) { const int index = mo.process(); ans1[index] = atc; ans2[index] = penalty; } REP(i, q) cout << ans1[i] << ' ' << ans2[i] << '\n'; return 0; }