結果

問題 No.789 範囲の合計
ユーザー ei1333333ei1333333
提出日時 2019-02-08 22:07:12
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 314 ms / 1,000 ms
コード長 658 bytes
コンパイル時間 1,907 ms
使用メモリ 24,768 KB
最終ジャッジ日時 2023-02-01 16:42:35
合計ジャッジ時間 5,857 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
4,904 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 298 ms
22,396 KB
testcase_03 AC 88 ms
4,900 KB
testcase_04 AC 314 ms
22,932 KB
testcase_05 AC 282 ms
22,392 KB
testcase_06 AC 291 ms
22,432 KB
testcase_07 AC 105 ms
4,904 KB
testcase_08 AC 256 ms
24,184 KB
testcase_09 AC 245 ms
22,936 KB
testcase_10 AC 270 ms
14,200 KB
testcase_11 AC 283 ms
24,768 KB
testcase_12 AC 306 ms
24,756 KB
testcase_13 AC 2 ms
4,900 KB
testcase_14 AC 1 ms
4,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

template< class T >
struct BinaryIndexedTree {
  unordered_map< int, T > data;

  BinaryIndexedTree() {
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) {
      if(data.count(k)) ret += data[k];
    }
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k <= (int) (1e9+5); k += k & -k) data[k] += x;
  }
};

int main() {
  int Q;
  cin >> Q;
  BinaryIndexedTree< int64 > bit;
  int64 add = 0;
  while(Q--) {
    int t, x, y;
    cin >> t >> x >> y;
    if(t == 0) bit.add(x, y);
    else add += bit.sum(y) - bit.sum(x - 1);
  }
  cout << add << endl;
}

0