Submission #68220


ソースコード

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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct Segtree{
ll n;
vector <ll> value;
Segtree(ll size){
n=1;
while(n<size){
n*=2;
}
value.resize(n*2);
for(ll i=0;i<n*2;i++){
value[i]=0;
}
}
void update(ll i,ll 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 get1(ll a,ll b){
return get(a,b+1,0,0,n);
}
ll get(ll a,ll b,ll i,ll l,ll r){
if(b<=l||r<=a){
return 0;
}
if(a<=l&&r<=b){
return (value[i]);
}
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);
// }
// ll get(ll a,ll b);
// return(a,b+1,0,0,n);
}
};
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
long long a,b,i,p=0;
cin>>a>>b;
long long s,r,d, v;
Segtree st(a);
for(i=0;i<b;i++){
cin>>s>>d>>r;
if(s==0){
st.update(d-1,r);
}else{
cout<<st.get1(d-1,r-1)<<endl;;
}
}
return (0);
}

ステータス

項目 データ
問題 0649 - 区間和(セグ木、BIT練習)
ユーザー名 R2120
投稿日時 2021-08-26 12:17:31
言語 C++17
状態 Accepted
得点 5
ソースコード長 1360 Byte
最大実行時間 1098 ms
最大メモリ使用量 104892 KB

セット

セット 得点 Cases
1 ALL 5 / 5 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
input100-1 AC 84 ms 860 KB
1
input100-2 AC 183 ms 1828 KB
1
input100-3 AC 376 ms 4208 KB
1
input100-4 AC 740 ms 9024 KB
1
input100-5 AC 1094 ms 16144 KB
1
input1000-1 AC 359 ms 18140 KB
1
input1000-2 AC 810 ms 23324 KB
1
input1000-3 AC 400 ms 25560 KB
1
input1000-4 AC 1009 ms 31764 KB
1
input1000-5 AC 306 ms 33496 KB
1
input10000-1 AC 967 ms 39572 KB
1
input10000-2 AC 1041 ms 45912 KB
1
input10000-3 AC 811 ms 50852 KB
1
input10000-4 AC 924 ms 56428 KB
1
input10000-5 AC 477 ms 59192 KB
1
input100000-1 AC 1098 ms 67464 KB
1
input100000-2 AC 181 ms 68308 KB
1
input100000-3 AC 192 ms 69280 KB
1
input100000-4 AC 588 ms 72560 KB
1
input100000-5 AC 1001 ms 78400 KB
1
input1000000-1 AC 144 ms 93324 KB
1
input1000000-2 AC 453 ms 95448 KB
1
input1000000-3 AC 500 ms 97956 KB
1
input1000000-4 AC 925 ms 102896 KB
1
input1000000-5 AC 427 ms 104892 KB
1
input1001000-1 AC 33 ms 88588 KB
1
input1001000-2 AC 17 ms 88540 KB
1
input1001000-3 AC 22 ms 88612 KB
1
input1001000-4 AC 20 ms 88688 KB
1
input1001000-5 AC 20 ms 88764 KB
1