結果
| 問題 | No.1441 MErGe | 
| コンテスト | |
| ユーザー |  ninoinui | 
| 提出日時 | 2021-03-27 01:00:48 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,880 bytes | 
| コンパイル時間 | 3,178 ms | 
| コンパイル使用メモリ | 230,072 KB | 
| 最終ジャッジ日時 | 2025-01-19 23:45:43 | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 3 WA * 25 | 
ソースコード
#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:
  int N, M;
  vector<T> B;
public:
  FenwickTree() : N(0) {}
  FenwickTree(int n) : N(n + 1), M(1), B(N, 0) {
    while (M * 2 <= N) M *= 2;
  }
  FenwickTree(const vector<T> &v) : N((int)v.size() + 1), M(1), B(N, 0) {
    for (int i = 0; i < N - 1; i++) add(i, v.at(i));
    while (M * 2 <= N) M *= 2;
  }
  void add(int i, T x) {
    i++;
    while (i < N) B.at(i) += x, i += i & -i;
  }
  void add(int l, int r, T x) {
    add(l, x);
    add(r + 1, -x);
  }
  T sum(int i) {
    i++;
    T ret = 0;
    while (i > 0) ret += B.at(i), i -= i & -i;
    return ret;
  }
  T sum(int l, int r) { return sum(r) - sum(l - 1); }
  T at(int i) { return sum(i) - sum(i - 1); }
  int lower_bound(T w) {
    if (w <= 0) return 0;
    int x = 0;
    for (int 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;
  }
  int upper_bound(T w) {
    if (w < 0) return 0;
    int x = 0;
    for (int 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;
  int N, Q;
  cin >> N >> Q;
  vector<long> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<tuple<int, int, int>> V(Q);
  for (int i = 0; i < Q; i++) {
    int a, b, c;
    cin >> a >> b >> c, b--, c--;
    V.at(i) = {a, b, c};
  }
  FenwickTree<long> FT(A);
  tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> T;
  for (int i = 0; i < N; i++) T.insert(i);
  for (const auto& [a, l, r] : V) {
    if (a == 1) {
      for (int 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';
    }
  }
}
            
            
            
        