-
Notifications
You must be signed in to change notification settings - Fork 0
/
A_to_B.cpp
77 lines (70 loc) · 1.32 KB
/
A_to_B.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD = (1e9) + 7;
ll binpow(ll a, ll b, ll m) {
if(a == 0) return 0;
a %= m;
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin >> n;
vector<ll> arr(n);
ll p = 1;
ll zCnt = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if(arr[i] == 0) {
zCnt += 1;
}else {
p = p * arr[i] % MOD;
}
}
ll q;
cin >> q;
for(int i = 0; i < q; i++) {
ll type, id;
cin >> type >> id;
id--;
if(type == 0) {
ll val;
cin >> val;
if(arr[id] == 0 && val != 0) {
zCnt -= 1;
p = p * val % MOD;
} else if(arr[id] != 0 && val != 0){
p = p * binpow(arr[id], MOD-2, MOD) % MOD;
p = p * val % MOD;
} else if(arr[id] != 0 && val == 0) {
zCnt += 1;
p = p * binpow(arr[id], MOD-2, MOD) % MOD;
}
arr[id] = val;
} else {
ll ans = 1;
if(zCnt == 0) {
ans = p * binpow(arr[id], MOD-2, MOD) % MOD;
} else if(zCnt != 0 && arr[id] != 0) {
ans = 0;
} else if(zCnt == 1 && arr[id] == 0) {
ans = p;
} else if(zCnt > 1){
ans = 0;
}
cout << ans << "\n";
}
}
return 0;
}