結果
問題 | No.2338 Range AtCoder Query |
ユーザー |
![]() |
提出日時 | 2023-06-02 22:03:02 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,379 bytes |
コンパイル時間 | 6,920 ms |
コンパイル使用メモリ | 269,648 KB |
実行使用メモリ | 34,816 KB |
最終ジャッジ日時 | 2024-12-28 18:03:08 |
合計ジャッジ時間 | 14,103 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 29 RE * 5 |
ソースコード
#if __INCLUDE_LEVEL__ == 0#include <bits/stdc++.h>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<int> p(n);vector<string> s(n);for (int i : iota(0, n)) {cin >> tie(p[i], s[i]);--p[i];}vector<int> l(q), r(q);for (int id : iota(0, q)) {cin >> tie(l[id], r[id]);--l[id];}vector<vector<int>> lst(m);for (int i : iota(0, n)) {lst[p[i]].push_back(i);}vector<pair<int, int>> ans(q);vector<vector<int>> ids(m);for (int id : iota(0, q)) {ids[l[id]].push_back(id);}atcoder::fenwick_tree<int> f_ac(n);atcoder::fenwick_tree<int> f_wa(n);vector<int> 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::viewsusing views::solve;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);solve();}#else // __INCLUDE_LEVEL__#include <atcoder/fenwicktree>namespace std {template <class T1, class T2>istream& operator>>(istream& is, pair<T1, T2>& p) {return is >> p.first >> p.second;}template <class... Ts>istream& operator>>(istream& is, tuple<Ts...>& t) {return apply([&is](auto&... xs) -> istream& { return (is >> ... >> xs); }, t);}template <class... Ts>istream& operator>>(istream& is, tuple<Ts&...>&& t) {return is >> t;}template <class R, enable_if_t<!is_convertible_v<R, string>>* = nullptr>auto operator>>(istream& is, R&& r) -> decltype(is >> *begin(r)) {for (auto&& e : r) {is >> e;}return is;}template <class T1, class T2>ostream& operator<<(ostream& os, const pair<T1, T2>& p) {return os << p.first << ' ' << p.second;}template <class... Ts>ostream& operator<<(ostream& os, const tuple<Ts...>& t) {auto f = [&os](const auto&... xs) -> ostream& {[[maybe_unused]] auto sep = "";((os << exchange(sep, " ") << xs), ...);return os;};return apply(f, t);}template <class R, enable_if_t<!is_convertible_v<R, string_view>>* = 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__