#include #ifdef LOCAL #include #else #define debug(...) void(0) #endif struct Mo { Mo(int n) : n(n) {} void add(int l, int r) { assert(l <= r); left.emplace_back(l); right.emplace_back(r); } template void run(const AL& add_left, const AR& add_right, const DL& del_left, const DR del_right, const REM& rem) { int q = left.size(), width = n / std::min(std::max(sqrt(q * 2 / 3), 1), n); std::vector order(q); std::iota(order.begin(), order.end(), 0); std::sort(order.begin(), order.end(), [&](int a, int b) { int ablock = left[a] / width, bblock = left[b] / width; if (ablock != bblock) return ablock < bblock; return (ablock & 1) ? (right[a] > right[b]) : (right[a] < right[b]); }); int l = 0, r = 0; for (auto idx : order) { while (l > left[idx]) add_left(--l); while (r < right[idx]) add_right(r++); while (l < left[idx]) del_left(l++); while (r > right[idx]) del_right(--r); rem(idx); } } template void run(const A& add, const D& del, const REM& rem) { run(add, add, del, del, rem); } private: int n; std::vector left, right; }; template struct BinaryTrie { struct Node { std::array nxt; int count; Node() : nxt{-1, -1}, count(0) {} }; std::vector nodes; inline int& next(int i, int j) { return nodes[i].nxt[j]; } BinaryTrie() { nodes.emplace_back(); } void insert(const T& x) { int cur = 0; for (int i = MAX_LOG - 1; i >= 0; i--) { int f = x >> i & 1; int nxt = next(cur, f); if (nxt == -1) { nxt = nodes.size(); next(cur, f) = nxt; nodes.emplace_back(); } nodes[cur].count++; cur = nxt; } nodes[cur].count++; } void erase(const T& x) { assert(count(x)); int cur = 0; for (int i = MAX_LOG - 1; i >= 0; i--) { int f = x >> i & 1; nodes[cur].count--; cur = next(cur, f); } nodes[cur].count--; } int find(const T& x) { int cur = 0; for (int i = MAX_LOG - 1; i >= 0; i--) { int f = x >> i & 1; cur = next(cur, f); if (cur == -1) return -1; } return cur; } int count(const T& x) { int idx = find(x); return idx == -1 ? 0 : nodes[idx].count; } T min_element(const T& xor_val = 0) { int cur = 0; T res = 0; for (int i = MAX_LOG - 1; i >= 0; i--) { int f = xor_val >> i & 1; int l = next(cur, f), r = next(cur, f ^ 1); if (l == -1 or nodes[l].count == 0) { cur = r; res |= T(f ^ 1) << i; } else { cur = l; res |= T(f) << i; } } return res; } T max_element(const T& xor_val = 0) { return min_element(~xor_val); } T kth_element(int k, const T& xor_val = 0) const { int cur = 0; T res = 0; for (int i = MAX_LOG - 1; i >= 0; i--) { int f = xor_val >> i & 1; int l = next(cur, f), r = next(cur, f ^ 1); if (l == -1 or nodes[l].count <= k) { cur = r; k -= (l == -1 ? 0 : nodes[l].count); res |= T(f ^ 1) << i; } else { cur = l; res |= T(f) << i; } } return res; } int count_less(const T& x, const T& xor_val = 0) { int cur = 0; int res = 0; for (int i = MAX_LOG - 1; i >= 0; i--) { int f = xor_val >> i & 1, g = x >> i & 1; int l = next(cur, f), r = next(cur, f ^ 1); if (f != g and l != -1) res += nodes[l].count; cur = next(cur, g); if (cur == -1) break; } return res; } }; using namespace std; typedef long long ll; #define all(x) begin(x), end(x) constexpr int INF = (1 << 30) - 1; constexpr long long IINF = (1LL << 60) - 1; constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; template istream& operator>>(istream& is, vector& v) { for (auto& x : v) is >> x; return is; } template ostream& operator<<(ostream& os, const vector& v) { auto sep = ""; for (const auto& x : v) os << exchange(sep, " ") << x; return os; } template bool chmin(T& x, U&& y) { return y < x and (x = forward(y), true); } template bool chmax(T& x, U&& y) { return x < y and (x = forward(y), true); } template void mkuni(vector& v) { sort(begin(v), end(v)); v.erase(unique(begin(v), end(v)), end(v)); } template int lwb(const vector& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, M, Q; cin >> N >> M >> Q; vector P(N), S(N); for (int i = 0; i < N; i++) { string tmp; cin >> P[i] >> tmp; P[i]--; S[i] = (tmp == "AC"); } Mo mo(N); for (int i = 0; i < Q; i++) { int L, R; cin >> L >> R; mo.add(--L, R); } vector> ac(M); vector> wa(M); int correct = 0, penalty = 0; auto calc = [&](int idx) { if (ac[idx].empty()) return 0; int x = *ac[idx].begin(); return wa[idx].count_less(x); }; auto add = [&](int idx) { int x = P[idx]; { correct -= (not ac[x].empty()); penalty -= calc(x); } if (S[idx] == 0) wa[x].insert(idx); else ac[x].emplace(idx); { correct += (not ac[x].empty()); penalty += calc(x); } }; auto del = [&](int idx) { int x = P[idx]; { correct -= (not ac[x].empty()); penalty -= calc(x); } if (S[idx] == 0) wa[x].erase(idx); else ac[x].erase(idx); { correct += (not ac[x].empty()); penalty += calc(x); } }; vector ans1(Q), ans2(Q); auto rem = [&](int idx) { ans1[idx] = correct; ans2[idx] = penalty; }; mo.run(add, del, rem); for (int i = 0; i < Q; i++) cout << ans1[i] << ' ' << ans2[i] << '\n'; return 0; }