結果

問題 No.789 範囲の合計
ユーザー ei1333333ei1333333
提出日時 2019-02-08 22:06:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 612 bytes
コンパイル時間 2,467 ms
コンパイル使用メモリ 204,464 KB
実行使用メモリ 57,004 KB
最終ジャッジ日時 2023-09-11 04:48:03
合計ジャッジ時間 9,864 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 906 ms
51,200 KB
testcase_03 AC 82 ms
4,380 KB
testcase_04 AC 843 ms
49,080 KB
testcase_05 AC 496 ms
43,468 KB
testcase_06 AC 586 ms
44,228 KB
testcase_07 AC 69 ms
4,380 KB
testcase_08 AC 418 ms
26,816 KB
testcase_09 AC 381 ms
24,728 KB
testcase_10 TLE -
testcase_11 AC 757 ms
54,776 KB
testcase_12 AC 709 ms
54,424 KB
testcase_13 WA -
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 {
  map< int, T > data;

  BinaryIndexedTree() {
  }

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

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

int main() {
  int Q;
  cin >> Q;
  BinaryIndexedTree< int > 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