結果
問題 | No.789 範囲の合計 |
ユーザー | ei1333333 |
提出日時 | 2019-02-08 22:06:45 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 654 bytes |
コンパイル時間 | 2,147 ms |
コンパイル使用メモリ | 204,764 KB |
実行使用メモリ | 24,836 KB |
最終ジャッジ日時 | 2023-09-14 03:41:22 |
合計ジャッジ時間 | 7,429 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 316 ms
22,324 KB |
testcase_03 | AC | 89 ms
4,380 KB |
testcase_04 | AC | 452 ms
22,852 KB |
testcase_05 | AC | 384 ms
22,552 KB |
testcase_06 | AC | 391 ms
22,376 KB |
testcase_07 | AC | 105 ms
4,376 KB |
testcase_08 | AC | 352 ms
24,164 KB |
testcase_09 | AC | 283 ms
22,932 KB |
testcase_10 | AC | 291 ms
14,260 KB |
testcase_11 | AC | 346 ms
24,688 KB |
testcase_12 | AC | 342 ms
24,836 KB |
testcase_13 | WA | - |
testcase_14 | AC | 1 ms
4,380 KB |
ソースコード
#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); 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; }