-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2042.py
More file actions
36 lines (32 loc) · 1 KB
/
Copy path2042.py
File metadata and controls
36 lines (32 loc) · 1 KB
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
import sys
rl = sys.stdin.readline
N, M, K = map(int, rl().split())
ns = [int(rl()) for _ in range(N)]
tree = [0]*(N*4)
def makeSegTree(start, end, node):
if start==end:
tree[node] = ns[start]
return tree[node]
mid = (start+end)//2
tree[node] = makeSegTree(start, mid, node*2)+makeSegTree(mid+1, end,node*2+1)
return tree[node]
makeSegTree(0,N-1,1)
def calSum(start, end, node, left, right):
if left > end or right < start: return 0
if left<=start and end<=right: return tree[node]
mid = (start+end)//2
return calSum(start,mid,node*2,left,right)+calSum(mid+1,end,node*2+1,left,right)
def update(start, end, node, idx, w):
if idx<start or idx>end: return
tree[node]+=w
if start==end: return
mid = (start+end)//2
update(start,mid,node*2,idx,w)
update(mid+1,end,node*2+1,idx,w)
for _ in range(M+K):
a, b, c = map(int, rl().split())
if a==1:
update(0,N-1,1,b-1,c-ns[b-1])
ns[b-1] = c
else:
print(calSum(0,N-1,1,b-1,c-1))