結果

問題 No.2338 Range AtCoder Query
ユーザー risujirohrisujiroh
提出日時 2023-06-02 21:57:38
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,179 bytes
コンパイル時間 5,627 ms
コンパイル使用メモリ 268,552 KB
実行使用メモリ 34,080 KB
最終ジャッジ日時 2023-08-28 03:23:41
合計ジャッジ時間 13,447 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 1 ms
4,356 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,352 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 165 ms
33,848 KB
testcase_32 AC 159 ms
34,080 KB
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

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(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);
  for (int x : iota(0, m)) {
    bool ac = false;
    for (int i : lst[x]) {
      ac |= s[i] == "AC";
    }
    if (!ac) {
      continue;
    }
    for (int i : lst[x]) {
      if (s[i] == "AC") {
        f_ac.add(i, 1);
        break;
      } else {
        f_wa.add(i, 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") {
      bool ac = false;
      for (auto it = upper_bound(lst[p[L]], L); it != lst[p[L]].end(); ++it) {
        ac |= s[*it] == "AC";
      }
      if (ac) {
        for (auto it = upper_bound(lst[p[L]], L); it != lst[p[L]].end(); ++it) {
          if (s[*it] == "AC") {
            f_ac.add(*it, 1);
            break;
          } else {
            f_wa.add(*it, 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