-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ12837.cpp
More file actions
46 lines (40 loc) · 960 Bytes
/
BOJ12837.cpp
File metadata and controls
46 lines (40 loc) · 960 Bytes
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
/*
알고리즘 : 세그먼트트리
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#define N 1000001
#define ll long long
using namespace std;
ll date[N*4]={0,};
int n,q,a,b,c;
void update(int dest,ll val,int idx, int left,int right){
if(dest<left||right<dest)
return;
date[idx]+=val;
if(left!=right){
update(dest,val,idx*2,left,(left+right)/2);
update(dest,val,idx*2+1,(left+right)/2+1,right);
}
}
ll sum(int st,int fi,int idx,int left,int right){
if(fi<left||right<st)
return 0;
if(st<=left&&right<=fi)
return date[idx];
return sum(st,fi,idx*2,left,(left+right)/2)+sum(st,fi,idx*2+1,(left+right)/2+1,right);
}
int main(){
cin>>n>>q;
for(int i=0;i<q;i++){
scanf("%d%d%d",&a,&b,&c);
if(a==1)
update(b,(ll)c,1,1,n);
else
printf("%lld\n",sum(b,c,1,1,n));
}
return 0;
}