Submission #68586
ソースコード
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 | #include<bits/stdc++.h> using namespace std; #define ll long long struct segtree{ int n; vector<ll> value; segtree( int size){ n=1; while (n<size){ n*=2; } value.resize(n*2); for ( int i=0;i<n*2;i++){ value[i]=0; } } void update( int i, int x){ i+=n-1; value[i]+=x; while (i>0){ i=(i-1)/2; value[i]=value[i*2+1]+value[i*2+2]; } } ll get( int a, int b){ return get(a,b+1,0,0,n); } ll get( int a, int b, int i, int l, int r){ if (b<=l || r<=a){ return 0; } if (a<=l && r<=b){ return value[i]; } else { ll le=get(a,b,i*2+1,l,(l+r)/2); ll ri=get(a,b,i*2+2,(l+r)/2,r); return le+ri; } } }; int main(){ int n,q,s,a,b; cin>>n>>q; segtree st(n); vector<ll> x; for ( int i=0;i<q;i++){ cin>>s>>a>>b; if (s==0){ st.update(a-1,b); } else if (s==1){ x.push_back(st.get(a-1,b-1)); } } for ( int i=0;i<x.size();i++){ cout<<x[i]<< "\n" ; } return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0649 - 区間和(セグ木、BIT練習) |
ユーザー名 | ei2109 |
投稿日時 | 2021-09-27 18:24:44 |
言語 | C++17 |
状態 | Accepted |
得点 | 5 |
ソースコード長 | 1251 Byte |
最大実行時間 | 623 ms |
最大メモリ使用量 | 121596 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 5 / 5 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input100-1 | AC | 74 ms | 1880 KB |
1
|
input100-2 | AC | 112 ms | 4944 KB |
1
|
input100-3 | AC | 287 ms | 11608 KB |
1
|
input100-4 | AC | 377 ms | 25128 KB |
1
|
input100-5 | AC | 533 ms | 33620 KB |
1
|
input1000-1 | AC | 187 ms | 33036 KB |
1
|
input1000-2 | AC | 412 ms | 40004 KB |
1
|
input1000-3 | AC | 201 ms | 40324 KB |
1
|
input1000-4 | AC | 526 ms | 49380 KB |
1
|
input1000-5 | AC | 166 ms | 48248 KB |
1
|
input10000-1 | AC | 516 ms | 56240 KB |
1
|
input10000-2 | AC | 566 ms | 63036 KB |
1
|
input10000-3 | AC | 442 ms | 67224 KB |
1
|
input10000-4 | AC | 515 ms | 73448 KB |
1
|
input10000-5 | AC | 265 ms | 74512 KB |
1
|
input100000-1 | AC | 623 ms | 84552 KB |
1
|
input100000-2 | AC | 118 ms | 82544 KB |
1
|
input100000-3 | AC | 123 ms | 83632 KB |
1
|
input100000-4 | AC | 329 ms | 88140 KB |
1
|
input100000-5 | AC | 555 ms | 95484 KB |
1
|
input1000000-1 | AC | 97 ms | 108368 KB |
1
|
input1000000-2 | AC | 279 ms | 112080 KB |
1
|
input1000000-3 | AC | 325 ms | 114784 KB |
1
|
input1000000-4 | AC | 582 ms | 120884 KB |
1
|
input1000000-5 | AC | 278 ms | 121596 KB |
1
|
input1001000-1 | AC | 22 ms | 104004 KB |
1
|
input1001000-2 | AC | 20 ms | 103836 KB |
1
|
input1001000-3 | AC | 26 ms | 103928 KB |
1
|
input1001000-4 | AC | 16 ms | 103888 KB |
1
|
input1001000-5 | AC | 25 ms | 103988 KB |
1
|