結果

問題 No.2338 Range AtCoder Query
ユーザー risujirohrisujiroh
提出日時 2023-06-02 22:06:01
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 236 ms / 4,000 ms
コード長 3,379 bytes
コンパイル時間 3,865 ms
コンパイル使用メモリ 268,944 KB
実行使用メモリ 34,852 KB
最終ジャッジ日時 2023-08-28 03:37:52
合計ジャッジ時間 11,565 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 166 ms
25,780 KB
testcase_12 AC 168 ms
25,536 KB
testcase_13 AC 172 ms
26,284 KB
testcase_14 AC 159 ms
26,580 KB
testcase_15 AC 192 ms
28,072 KB
testcase_16 AC 225 ms
32,564 KB
testcase_17 AC 234 ms
32,612 KB
testcase_18 AC 223 ms
32,536 KB
testcase_19 AC 236 ms
32,680 KB
testcase_20 AC 224 ms
32,596 KB
testcase_21 AC 212 ms
32,572 KB
testcase_22 AC 229 ms
32,612 KB
testcase_23 AC 214 ms
32,600 KB
testcase_24 AC 211 ms
32,584 KB
testcase_25 AC 220 ms
32,596 KB
testcase_26 AC 101 ms
25,712 KB
testcase_27 AC 97 ms
25,708 KB
testcase_28 AC 100 ms
25,676 KB
testcase_29 AC 196 ms
32,592 KB
testcase_30 AC 218 ms
32,464 KB
testcase_31 AC 164 ms
34,712 KB
testcase_32 AC 164 ms
34,852 KB
testcase_33 AC 166 ms
29,960 KB
testcase_34 AC 168 ms
29,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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(n);
  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::views

using 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__
0