-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11505.cpp
More file actions
105 lines (96 loc) · 1.94 KB
/
Copy path11505.cpp
File metadata and controls
105 lines (96 loc) · 1.94 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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <stdio.h>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long dtype;
class SegmentTree
{
public:
vector<dtype> tree;
int s;
SegmentTree(int n)
{
for (s = 1; s <= n; s *= 2)
{
}
tree.resize(s * 2);
for (int i = 0; i < s * 2; i++)
{
tree[i] = 0;
}
}
void insert(vector<dtype> &d)
{
for (int i = s; i < s + d.size(); i++)
{
tree[i] = d[i - s];
}
for (int i = s - 1; i > 0; i--)
{
tree[i] = (tree[i * 2] * tree[i * 2 + 1]) % MOD;
}
}
dtype getMulti(int Left, int Right)
{
int l = Left + s - 1, r = Right + s - 1;
dtype rval = 1;
while (l <= r)
{
if (l % 2 == 0)
{
l /= 2;
}
else
{
rval = (rval * tree[l]) % MOD;
l = l / 2 + 1;
}
if (r % 2 == 1)
{
r /= 2;
}
else
{
rval = (rval * tree[r]) % MOD;
r = r / 2 - 1;
}
}
return rval;
}
void update(int index, dtype val)
{
int idx = index + s - 1;
tree[idx] = val;
while (idx)
{
idx /= 2;
tree[idx] = (tree[idx * 2] * tree[idx * 2 + 1]) % MOD;
}
}
};
vector<dtype> arr;
int main()
{
int N, M, K, a, b, c;
scanf("%d %d %d", &N, &M, &K);
arr.assign(N, 0);
for (int i = 0; i < N; i++)
{
scanf("%lld", &arr[i]);
}
SegmentTree t(N);
t.insert(arr);
for (int i = 0; i < M + K; i++)
{
scanf("%d %d %d", &a, &b, &c);
if (a == 1)
{
t.update(b, (dtype)c);
}
else if (a == 2)
{
printf("%lld\n", t.getMulti(b, c));
}
}
return 0;
}