Submission #41921
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #include <iostream> #include <string> #include <stack> #include <queue> #include <cstring> #include <algorithm> #include <vector> //#include <cstdio> #include <cmath> #include <cstdlib> #include <functional> #include <map> #include <numeric> using namespace std; #define elif else if #define echo cout << #define read cin >> #define fin << '\n' #define finn cout << '\n' #define forin(i, n) for ( int i = 0; i < n; i++ ) #define unless(flg) if(!(flg)) #define zu >> #define und << #define alles(obj) obj.begin(), obj.end() #define bash push_back #define makePair make_pair // type-define #define String string #define Stack stack #define Queue queue #define pQueue priority_queue #define Vector vector #define Pair pair #define Map map typedef long long llong; typedef bool boolean; typedef Pair< int , int > Pii; typedef Vector< int > Vi; // utils const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; boolean isMovable( int x, int y, int w, int h){ return (x>=0&&y>=0&&x<w&&y<h);}; const int INF = 1 << 29; #define int long long struct BinaryIndexedTree{ llong bit[1 << 20] = {}; int n; BinaryIndexedTree( int a){ n = a; } llong sum( int i){ int s = 0; while ( i > 0 ) { s += bit[i]; i -= i & -i; } return s; } void add( int i, int x) { while ( i <= n ) { bit[i] += x; i += i & -i; } } }; BinaryIndexedTree binaryIndexedTree(1000100); signed main(){ cin.tie(0); ios::sync_with_stdio( false ); int n, q; read n >> q; for ( int i = 0; i < q; i++ ) { int s, a, b; read s >> a >> b; if ( s ) { echo binaryIndexedTree.sum(b) - binaryIndexedTree.sum(a-1) fin; } else { binaryIndexedTree.add(a, b); } } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0649 - 区間和(セグ木、BIT練習) |
ユーザー名 | r1825 |
投稿日時 | 2018-08-26 11:36:16 |
言語 | C++14 |
状態 | Accepted |
得点 | 5 |
ソースコード長 | 1966 Byte |
最大実行時間 | 212 ms |
最大メモリ使用量 | 96872 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 5 / 5 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input100-1 | AC | 35 ms | 9056 KB |
1
|
input100-2 | AC | 51 ms | 10288 KB |
1
|
input100-3 | AC | 88 ms | 12540 KB |
1
|
input100-4 | AC | 144 ms | 17100 KB |
1
|
input100-5 | AC | 212 ms | 24348 KB |
1
|
input1000-1 | AC | 83 ms | 26480 KB |
1
|
input1000-2 | AC | 176 ms | 31420 KB |
1
|
input1000-3 | AC | 83 ms | 33680 KB |
1
|
input1000-4 | AC | 188 ms | 39904 KB |
1
|
input1000-5 | AC | 79 ms | 41772 KB |
1
|
input10000-1 | AC | 193 ms | 47484 KB |
1
|
input10000-2 | AC | 199 ms | 53712 KB |
1
|
input10000-3 | AC | 158 ms | 58656 KB |
1
|
input10000-4 | AC | 184 ms | 64368 KB |
1
|
input10000-5 | AC | 107 ms | 67136 KB |
1
|
input100000-1 | AC | 212 ms | 73484 KB |
1
|
input100000-2 | AC | 63 ms | 74460 KB |
1
|
input100000-3 | AC | 63 ms | 75568 KB |
1
|
input100000-4 | AC | 123 ms | 78720 KB |
1
|
input100000-5 | AC | 179 ms | 84560 KB |
1
|
input1000000-1 | AC | 46 ms | 85024 KB |
1
|
input1000000-2 | AC | 95 ms | 87156 KB |
1
|
input1000000-3 | AC | 103 ms | 89668 KB |
1
|
input1000000-4 | AC | 180 ms | 94740 KB |
1
|
input1000000-5 | AC | 104 ms | 96872 KB |
1
|
input1001000-1 | AC | 27 ms | 96820 KB |
1
|
input1001000-2 | AC | 21 ms | 96776 KB |
1
|
input1001000-3 | AC | 25 ms | 96728 KB |
1
|
input1001000-4 | AC | 20 ms | 96808 KB |
1
|
input1001000-5 | AC | 22 ms | 96756 KB |
1
|