File tree Expand file tree Collapse file tree 1 file changed +91
-0
lines changed Expand file tree Collapse file tree 1 file changed +91
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ using namespace std ;
3
+
4
+ const int mod = 1e9 + 7 ;
5
+ const int nodesize = 1e6 + 1 ;
6
+ unsigned long long tree[nodesize << 2 ];
7
+ int n, m, k;
8
+ int unit;
9
+
10
+ void getUnit () {
11
+ unit = 2 ;
12
+ while (1 ) {
13
+ if (unit >= n) {
14
+ break ;
15
+ }
16
+ unit *= 2 ;
17
+ }
18
+ }
19
+
20
+ void input () {
21
+ cin >> n >> m >> k;
22
+ getUnit ();
23
+ fill (tree, tree + (nodesize << 2 ), 1 );
24
+ for (int i = 0 ; i < n; i++) {
25
+ cin >> tree[i+unit];
26
+ }
27
+ }
28
+
29
+ void buildTree () {
30
+ for (int i = unit - 1 ; i > 0 ; i--) {
31
+ tree[i] = (tree[i * 2 ] * tree[i * 2 + 1 ]);
32
+ tree[i] %= mod;
33
+ }
34
+ }
35
+
36
+ void update (int index, int value) {
37
+ --index; index += unit;
38
+ unsigned long long before = tree[index];
39
+ tree[index] = value;
40
+ index /= 2 ;
41
+ while (index > 0 ) {
42
+ tree[index] = tree[index * 2 ] * tree[index * 2 + 1 ];
43
+ tree[index] %= mod;
44
+ index /= 2 ;
45
+ }
46
+ }
47
+
48
+ unsigned long long query (int start, int end) {
49
+ unsigned long long answer = 1 ;
50
+ if (start > end) swap (start, end);
51
+ start--; end--; start += unit; end += unit;
52
+ while (start <= end) {
53
+ if (start % 2 ) {
54
+ answer *= tree[start];
55
+ answer %= mod;
56
+ ++start;
57
+ }
58
+ if (!(end % 2 )) {
59
+ answer *= tree[end];
60
+ answer %= mod;
61
+ --end;
62
+ }
63
+ start /= 2 ;
64
+ end /= 2 ;
65
+ }
66
+ return answer;
67
+ }
68
+
69
+ void solve () {
70
+ input ();
71
+ buildTree ();
72
+ int cmd, b, c;
73
+ m += k;
74
+ while (m--) {
75
+ cin >> cmd >> b >> c;
76
+ if (cmd == 1 ) {
77
+ update (b, c);
78
+ } else {
79
+ cout << query (b, c) << ' \n ' ;
80
+ }
81
+ }
82
+ }
83
+
84
+ int main () {
85
+ ios_base::sync_with_stdio (false );
86
+ cin.tie (NULL );
87
+ cout.tie (NULL );
88
+
89
+ solve ();
90
+ return 0 ;
91
+ }
You can’t perform that action at this time.
0 commit comments