-
Notifications
You must be signed in to change notification settings - Fork 0
/
11505.py
72 lines (62 loc) · 1.46 KB
/
11505.py
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
import sys
input=sys.stdin.readline
n,m,k=map(int,input().split())
MOD=10**9+7
arr=[0]*(n+1)
tree=[1]*(n+1)
zerotree=[0]*(n+1)
zero=[False]*(n+1)
def prefix_sum(i):
result=0
while i>0:
result+=zerotree[i]
i-=(i&-i)
return result
def sum_update(i,diff):
while i<=n:
zerotree[i]+=diff
i+=(i&-i)
def interval_sum(start,end):
return prefix_sum(end)-prefix_sum(start-1)
def prefix_mul(i):
result=1
while i>0:
result=(result*tree[i])%MOD
i-=(i&-i)
return result
def update(i,diff):
while i<=n:
tree[i]=(tree[i]*diff)%MOD
i+=(i&-i)
def interval_mul(start,end):
return prefix_mul(end)*pow(prefix_mul(start-1),MOD-2,MOD)%MOD
for i in range(1,n+1):
x=int(input())
arr[i]=x
if x==0:
update(i,1)
zero[i]=True
sum_update(i,1)
else:
update(i,x)
for i in range(m+k):
# print(tree)
a,b,c=map(int,input().split())
if a==1:
if zero[b] and c==0:
continue
if c==0 and not zero[b]:
c=1
sum_update(b,1)
zero[b]=True
else:
if zero[b]:
sum_update(b,-1)
zero[b]=False
update(b,c*pow(arr[b],MOD-2,MOD)%MOD)
arr[b]=c
else:
if interval_sum(b,c)!=0:
print(0)
else:
print(interval_mul(b,c))