結果

問題 No.1441 MErGe
ユーザー ninoinuininoinui
提出日時 2021-03-27 01:03:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,908 bytes
コンパイル時間 2,592 ms
コンパイル使用メモリ 239,588 KB
実行使用メモリ 23,680 KB
最終ジャッジ日時 2024-05-06 18:57:22
合計ジャッジ時間 10,585 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
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 AC 226 ms
23,680 KB
testcase_29 AC 227 ms
23,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC diagnostic warning "-Wextra"
#pragma GCC diagnostic warning "-Wshadow"
#include <bits/stdc++.h>
using namespace std;

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); }
template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); }
template <class A, class B> ostream& operator<<(ostream& os, pair<A, B>& p) { return os << '(' << p.first << ", " << p.second << ')'; }
static bool debug = false;
void dump() {}
template <class A, class... B> void dump(A&& a, B&&... b) { if (debug) cout << a << (sizeof...(b) ? ' ' : '\n'), dump(b...); }
template <class A> void dump1D(A& a) { if (debug) for (auto i = a.begin(); i != a.end(); i++) cout << *i << (next(i) != a.end() ? ' ' : '\n'); }
template <class A> void dump2D(A& a) { if (debug) for (auto i = a.begin(); i != a.end(); i++) dump1D(*i), cout << (next(i) != a.end() ? "" : "\n"); }

template <typename T> class FenwickTree {
private:
  long N, M;
  vector<T> B;

public:
  FenwickTree() : N(0) {}
  FenwickTree(long n) : N(n + 1), M(1), B(N, 0) {
    while (M * 2 <= N) M *= 2;
  }
  FenwickTree(const vector<T> &v) : N((long)v.size() + 1), M(1), B(N, 0) {
    for (long i = 0; i < N - 1; i++) add(i, v.at(i));
    while (M * 2 <= N) M *= 2;
  }
  void add(long i, T x) {
    i++;
    while (i < N) B.at(i) += x, i += i & -i;
  }
  void add(long l, long r, T x) {
    add(l, x);
    add(r + 1, -x);
  }
  T sum(long i) {
    i++;
    T ret = 0;
    while (i > 0) ret += B.at(i), i -= i & -i;
    return ret;
  }
  T sum(long l, long r) { return sum(r) - sum(l - 1); }
  T at(long i) { return sum(i) - sum(i - 1); }
  long lower_bound(T w) {
    if (w <= 0) return 0;
    long x = 0;
    for (long k = M; k > 0; k /= 2) {
      if (x + k <= N - 1 && B.at(x + k) < w) {
        w -= B.at(x + k);
        x += k;
      }
    }
    return x;
  }
  long upper_bound(T w) {
    if (w < 0) return 0;
    long x = 0;
    for (long k = M; k > 0; k /= 2) {
      if (x + k <= N - 1 && B.at(x + k) <= w) {
        w -= B.at(x + k);
        x += k;
      }
    }
    return x;
  }
};

signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  debug = true;

  long N, Q;
  cin >> N >> Q;
  vector<long> A(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);
  vector<tuple<long, long, long>> V(Q);
  for (long i = 0; i < Q; i++) {
    long a, b, c;
    cin >> a >> b >> c, b--, c--;
    V.at(i) = {a, b, c};
  }

  FenwickTree<long> FT(A);
  tree<long, null_type, less<long>, rb_tree_tag, tree_order_statistics_node_update> T;
  for (long i = 0; i < N; i++) T.insert(i);

  for (const auto& [a, l, r] : V) {
    if (a == 1) {
      for (long i = r; i > l; i--) T.erase(*T.find_by_order(i));
    } else {
      cout << FT.sum(*T.find_by_order(l), *T.find_by_order(r)) << '\n';
    }
  }
}
0