結果

問題 No.833 かっこいい電車
ユーザー pekempeypekempey
提出日時 2019-05-25 16:40:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 156 ms / 2,000 ms
コード長 991 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 82,084 KB
実行使用メモリ 8,660 KB
最終ジャッジ日時 2023-09-14 21:03:03
合計ジャッジ時間 4,328 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
5,808 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 118 ms
6,040 KB
testcase_11 AC 156 ms
7,516 KB
testcase_12 AC 47 ms
4,976 KB
testcase_13 AC 33 ms
4,376 KB
testcase_14 AC 124 ms
7,464 KB
testcase_15 AC 63 ms
5,656 KB
testcase_16 AC 52 ms
6,500 KB
testcase_17 AC 42 ms
4,376 KB
testcase_18 AC 139 ms
6,184 KB
testcase_19 AC 49 ms
6,148 KB
testcase_20 AC 14 ms
4,388 KB
testcase_21 AC 113 ms
4,620 KB
testcase_22 AC 87 ms
8,048 KB
testcase_23 AC 56 ms
6,204 KB
testcase_24 AC 86 ms
7,776 KB
testcase_25 AC 134 ms
5,668 KB
testcase_26 AC 61 ms
6,768 KB
testcase_27 AC 97 ms
6,028 KB
testcase_28 AC 69 ms
4,664 KB
testcase_29 AC 81 ms
5,500 KB
testcase_30 AC 92 ms
8,660 KB
testcase_31 AC 129 ms
5,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>

using namespace std;

struct BIT {
  vector<long long> S;

  BIT(int n) : S(n + 1) {}

  void add(int k, long long v) {
    for (int i = k + 1; i < S.size(); i += i & -i) {
      S[i] += v;
    }
  }

  long long sum(int k) {
    long long res = 0;
    for (int i = k; i > 0; i -= i & -i) {
      res += S[i];
    }
    return res;
  }
};


int main() {
  int n, q;
  cin >> n >> q;
  BIT bit(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    bit.add(i, x);
  }
  set<int> st;
  for (int i = 0; i <= n; i++) {
    st.insert(i);
  }
  while (q--) {
    int type, x;
    cin >> type >> x;
    x--;
    if (type == 1) {
      st.erase(x+1);
    } else if (type == 2) {
      st.insert(x+1);
    } else if (type == 3) {
      bit.add(x, 1);
    } else {
      int r = *st.upper_bound(x);
      int l = *prev(st.upper_bound(x));
      cout << bit.sum(r) - bit.sum(l) << '\n';
    }
  }
}
0