#if __INCLUDE_LEVEL__ == 0 #include using namespace std; #undef assert #define assert(expr) (expr) || (__builtin_unreachable(), 0) #include __BASE_FILE__ namespace std::ranges::views { namespace { void solve() { int n, m, q; cin >> tie(n, m, q); vector p(n); vector s(n); for (int i : iota(0, n)) { cin >> tie(p[i], s[i]); --p[i]; } vector l(q), r(q); for (int id : iota(0, q)) { cin >> tie(l[id], r[id]); --l[id]; } vector> lst(m); for (int i : iota(0, n)) { lst[p[i]].push_back(i); } vector> ans(q); vector> ids(m); for (int id : iota(0, q)) { ids[l[id]].push_back(id); } atcoder::fenwick_tree f_ac(n); atcoder::fenwick_tree f_wa(n); vector memo(n); for (int x : iota(0, m)) { int pos = -1; for (int i : lst[x]) { if (s[i] == "AC") { pos = i; break; } } if (~pos) { for (int i : lst[x]) { if (i == pos) { f_ac.add(pos, 1); break; } else { memo[i] = pos; f_wa.add(pos, 1); } } } } for (int L : iota(0, n)) { for (int id : ids[L]) { ans[id] = {f_ac.sum(l[id], r[id]), f_wa.sum(l[id], r[id])}; } if (s[L] == "AC") { int pos = -1; for (auto it = upper_bound(lst[p[L]], L); it != lst[p[L]].end(); ++it) { if (s[*it] == "AC") { pos = *it; break; } } if (~pos) { for (auto it = upper_bound(lst[p[L]], L); it != lst[p[L]].end(); ++it) { if (*it == pos) { f_ac.add(pos, 1); break; } else { memo[*it] = pos; f_wa.add(pos, 1); } } } } else { f_wa.add(memo[L], -1); } } for (auto e : ans) { cout << e << '\n'; } } } // namespace } // namespace std::ranges::views using views::solve; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); } #else // __INCLUDE_LEVEL__ #include namespace std { template istream& operator>>(istream& is, pair& p) { return is >> p.first >> p.second; } template istream& operator>>(istream& is, tuple& t) { return apply([&is](auto&... xs) -> istream& { return (is >> ... >> xs); }, t); } template istream& operator>>(istream& is, tuple&& t) { return is >> t; } template >* = nullptr> auto operator>>(istream& is, R&& r) -> decltype(is >> *begin(r)) { for (auto&& e : r) { is >> e; } return is; } template ostream& operator<<(ostream& os, const pair& p) { return os << p.first << ' ' << p.second; } template ostream& operator<<(ostream& os, const tuple& t) { auto f = [&os](const auto&... xs) -> ostream& { [[maybe_unused]] auto sep = ""; ((os << exchange(sep, " ") << xs), ...); return os; }; return apply(f, t); } template >* = nullptr> auto operator<<(ostream& os, R&& r) -> decltype(os << *begin(r)) { auto sep = ""; for (auto&& e : r) { os << exchange(sep, " ") << e; } return os; } } // namespace std #endif // __INCLUDE_LEVEL__