結果

問題 No.789 範囲の合計
ユーザー ei1333333ei1333333
提出日時 2019-02-08 22:07:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 464 ms / 1,000 ms
コード長 658 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 205,744 KB
実行使用メモリ 24,764 KB
最終ジャッジ日時 2023-09-14 03:41:37
合計ジャッジ時間 7,100 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 457 ms
22,256 KB
testcase_03 AC 90 ms
4,376 KB
testcase_04 AC 464 ms
22,856 KB
testcase_05 AC 387 ms
22,224 KB
testcase_06 AC 395 ms
22,256 KB
testcase_07 AC 108 ms
4,376 KB
testcase_08 AC 365 ms
24,296 KB
testcase_09 AC 332 ms
22,984 KB
testcase_10 AC 354 ms
14,324 KB
testcase_11 AC 409 ms
24,764 KB
testcase_12 AC 403 ms
24,652 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 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