結果

問題 No.833 かっこいい電車
ユーザー cotton_fn_cotton_fn_
提出日時 2019-05-24 23:51:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 1,989 bytes
コンパイル時間 1,375 ms
コンパイル使用メモリ 121,384 KB
実行使用メモリ 9,356 KB
最終ジャッジ日時 2023-09-14 20:58:52
合計ジャッジ時間 5,082 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
6,288 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 124 ms
6,492 KB
testcase_11 AC 166 ms
8,272 KB
testcase_12 AC 50 ms
5,088 KB
testcase_13 AC 34 ms
4,380 KB
testcase_14 AC 133 ms
8,076 KB
testcase_15 AC 66 ms
6,028 KB
testcase_16 AC 54 ms
6,960 KB
testcase_17 AC 43 ms
4,376 KB
testcase_18 AC 148 ms
6,412 KB
testcase_19 AC 52 ms
6,404 KB
testcase_20 AC 14 ms
4,404 KB
testcase_21 AC 119 ms
4,892 KB
testcase_22 AC 90 ms
8,584 KB
testcase_23 AC 59 ms
6,792 KB
testcase_24 AC 89 ms
8,284 KB
testcase_25 AC 139 ms
6,200 KB
testcase_26 AC 63 ms
7,240 KB
testcase_27 AC 102 ms
6,552 KB
testcase_28 AC 71 ms
4,708 KB
testcase_29 AC 86 ms
5,764 KB
testcase_30 AC 100 ms
9,356 KB
testcase_31 AC 130 ms
6,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

template<class T, class F = plus<T>>
struct Fenwick {
  i64 n;
  vector<T> c;
  F f;
  Fenwick(i64 n, F f = plus<T>(), T init = T())
    : n(n), c(n + 1, init), f(f) {}
  T sum(i64 i) {
    return i > 0 ? f(sum(i - (i & -i)), c[i]) : T();
  }
  void add(i64 i, i64 x) {
    if (i <= n) {
      c[i] = f(c[i], x);
      add(i + (i & -i), x);
    }
  }
};
template<class T, class F>
Fenwick<T, F> make_fenwick(i64 n, F f, T init = T()) {
  return Fenwick<T, F>(n, f, init);
}
i64 n, q;
vector<i64> a;
int main() {
  cin >> n >> q;
  read_n(a, n);
  Fenwick<i64> fen(n + 2);
  set<i64> st;
  for (i64 i = 1; i <= n; ++i) {
    fen.add(i, a[i - 1]);
    st.insert(i);
  }
  st.insert(n + 1);
  while (q--) {
    i64 c, x; cin >> c >> x;
    if (c <= 2) {
      auto r = st.find(x + 1);
      if (c == 1 && r != end(st)) st.erase(x + 1);
      if (c == 2 && r == end(st)) st.insert(x + 1);
    } else if (c == 3) {
      fen.add(x, 1);
    } else {
      auto r = st.lower_bound(x + 1), l = r;
      --l;
      // cout << *l << '\t' << *r << '\n';
      cout << fen.sum(*r - 1) - fen.sum(*l - 1) << '\n';
    }
  }
  return 0;
}
0