Submission #68221


ソースコード

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{
long long n;
vector <long> 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(long i,long 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(long a,long 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];
}
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(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
long n,q,i;
cin>>n>>q;
long s,a,b;
vector<long> v;
segtree st(n);
for(i=0;i<q;i++){
cin>>s>>a>>b;
if(s==0){
st.update(a-1,b);
}else{
v.push_back(st.get1(a-1,b-1));
}
}
for(i=0;i<v.size();i++){
cout<<v[i]<<endl;
}
return 0;
}

ステータス

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

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
input100-1 AC 89 ms 1368 KB
1
input100-2 AC 183 ms 2620 KB
1
input100-3 AC 367 ms 5548 KB
1
input100-4 AC 757 ms 12128 KB
1
input100-5 AC 1083 ms 20012 KB
1
input1000-1 AC 361 ms 19396 KB
1
input1000-2 AC 824 ms 26080 KB
1
input1000-3 AC 408 ms 26692 KB
1
input1000-4 AC 1014 ms 35224 KB
1
input1000-5 AC 337 ms 34632 KB
1
input10000-1 AC 986 ms 43632 KB
1
input10000-2 AC 1031 ms 49452 KB
1
input10000-3 AC 785 ms 54520 KB
1
input10000-4 AC 947 ms 60120 KB
1
input10000-5 AC 481 ms 60900 KB
1
input100000-1 AC 1082 ms 71688 KB
1
input100000-2 AC 191 ms 68956 KB
1
input100000-3 AC 192 ms 70028 KB
1
input100000-4 AC 571 ms 74512 KB
1
input100000-5 AC 982 ms 81960 KB
1
input1000000-1 AC 140 ms 93696 KB
1
input1000000-2 AC 421 ms 96752 KB
1
input1000000-3 AC 505 ms 99560 KB
1
input1000000-4 AC 919 ms 107052 KB
1
input1000000-5 AC 407 ms 106256 KB
1
input1001000-1 AC 19 ms 88768 KB
1
input1001000-2 AC 23 ms 88708 KB
1
input1001000-3 AC 21 ms 88644 KB
1
input1001000-4 AC 20 ms 88584 KB
1
input1001000-5 AC 20 ms 88532 KB
1