Submission #54810


ソースコード

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
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
vector<long long> value;
int N;
void update(int i,long 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];
}
}
long long query(int a,int b,int k,int l,int r){
if(r<=a || b<=l) return 0;
if(a<=l && r<=b)
return value[k];
else{
long long c1=query(a,b,2*k+1,l,(l+r)/2);
long long c2=query(a,b,2*k+2,(l+r)/2,r);
return (c1+c2);
}
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
long long n,q,s,a,b;
cin>>n>>q;
N=1;
while(N<n) N*=2;
value=vector<long long>(2*N+10,0);
for(int i=0;i<q;i++){
cin>>s>>a>>b;
if(s==0){
update(a,b);
}
if(s==1){
cout<<query(a,b+1,0,1,N)<<'\n';
}
}
return(0);
}

ステータス

項目 データ
問題 0649 - 区間和(セグ木、BIT練習)
ユーザー名 ei1918
投稿日時 2019-09-13 17:48:54
言語 C++
状態 Accepted
得点 5
ソースコード長 1461 Byte
最大実行時間 304 ms
最大メモリ使用量 119240 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
input100-1 AC 37 ms 988 KB
1
input100-2 AC 52 ms 1956 KB
1
input100-3 AC 90 ms 4332 KB
1
input100-4 AC 155 ms 9008 KB
1
input100-5 AC 264 ms 15988 KB
1
input1000-1 AC 92 ms 18108 KB
1
input1000-2 AC 189 ms 23144 KB
1
input1000-3 AC 92 ms 25364 KB
1
input1000-4 AC 229 ms 31808 KB
1
input1000-5 AC 90 ms 33648 KB
1
input10000-1 AC 256 ms 39700 KB
1
input10000-2 AC 256 ms 45912 KB
1
input10000-3 AC 212 ms 50716 KB
1
input10000-4 AC 237 ms 56416 KB
1
input10000-5 AC 126 ms 59176 KB
1
input100000-1 AC 293 ms 67308 KB
1
input100000-2 AC 67 ms 69424 KB
1
input100000-3 AC 68 ms 70384 KB
1
input100000-4 AC 169 ms 72496 KB
1
input100000-5 AC 260 ms 78452 KB
1
input1000000-1 AC 70 ms 108984 KB
1
input1000000-2 AC 155 ms 109564 KB
1
input1000000-3 AC 174 ms 111804 KB
1
input1000000-4 AC 304 ms 114176 KB
1
input1000000-5 AC 149 ms 119240 KB
1
input1001000-1 AC 15 ms 88588 KB
1
input1001000-2 AC 28 ms 88528 KB
1
input1001000-3 AC 24 ms 88472 KB
1
input1001000-4 AC 21 ms 88540 KB
1
input1001000-5 AC 19 ms 88616 KB
1