CF1141F Please, another Queries on Array?

没啥好说

考虑质数60个,用二进制保存状态即可。

代码
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<ll, ll>
#define mk make_pair
const ll N = 4e5 + 10;
const ll mod = 1e9 + 7;
ll read()
{
ll x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + c - '0', c = getchar();
return x * f;
}
ll qpow(ll a, ll x, ll mo)
{
ll res = 1;
while (x)
{
if (x & 1)
res = 1ll * res * a % mo;
a = 1ll * a * a % mo;
x >>= 1;
}
return res;
}
const ll SEN = 4e5 + 10;
struct segmentTree
{
ll sum[SEN << 2], lazy[SEN << 2];
void addtag(ll pos, ll l, ll r, ll w)
{
lazy[pos] |= w;
sum[pos] |= w;
}
void pushdown(ll pos, ll l, ll r)
{
if (lazy[pos])
{
ll w = lazy[pos];
ll mid = (l + r) >> 1;
addtag(pos << 1, l, mid, w);
addtag(pos << 1 | 1, mid + 1, r, w);
lazy[pos] = 0;
}
}
void pushup(ll pos)
{
sum[pos] = sum[pos << 1 | 1] | sum[pos << 1];
}
ll query(ll ql, ll qr, ll pos, ll l, ll r)
{
if (ql <= l && r <= qr)
{
return sum[pos];
}
pushdown(pos, l, r);
ll mid = (l + r) >> 1;
ll ans = 0;
if (ql <= mid)
ans |= query(ql, qr, pos << 1, l, mid);
if (qr > mid)
ans |= query(ql, qr, pos << 1 | 1, mid + 1, r);
return ans;
}
void update(ll ql, ll qr, ll w, ll pos, ll l, ll r)
{
if (ql <= l && r <= qr)
{
addtag(pos, l, r, w);
return;
}
pushdown(pos, l, r);
ll mid = (l + r) >> 1;

if (ql <= mid)
update(ql, qr, w, pos << 1, l, mid);
if (qr > mid)
update(ql, qr, w, pos << 1 | 1, mid + 1, r);
pushup(pos);
}
} T1;
struct segmentTree2
{
ll sum[SEN << 2], lazy[SEN << 2];
void addtag(ll pos, ll l, ll r, ll w)
{
lazy[pos] = 1ll * lazy[pos] * w % mod;
sum[pos] = 1ll * sum[pos] * qpow(w, r - l + 1, mod) % mod;
}
void pushdown(ll pos, ll l, ll r)
{
if (lazy[pos] > 1)
{
ll w = lazy[pos];
ll mid = (l + r) >> 1;
addtag(pos << 1, l, mid, w);
addtag(pos << 1 | 1, mid + 1, r, w);
lazy[pos] = 1;
}
}
void pushup(ll pos)
{
sum[pos] = 1ll * sum[pos << 1 | 1] * sum[pos << 1] % mod;
}
ll query(ll ql, ll qr, ll pos, ll l, ll r)
{
if (ql <= l && r <= qr)
{
return sum[pos];
}
pushdown(pos, l, r);
ll mid = (l + r) >> 1;
ll ans = 1;
if (ql <= mid)
ans = 1ll * ans * query(ql, qr, pos << 1, l, mid) % mod;
if (qr > mid)
ans = 1ll * ans * query(ql, qr, pos << 1 | 1, mid + 1, r) % mod;
return ans;
}
void update(ll ql, ll qr, ll w, ll pos, ll l, ll r)
{
if (ql <= l && r <= qr)
{
addtag(pos, l, r, w);
return;
}
pushdown(pos, l, r);
ll mid = (l + r) >> 1;

if (ql <= mid)
update(ql, qr, w, pos << 1, l, mid);
if (qr > mid)
update(ql, qr, w, pos << 1 | 1, mid + 1, r);
pushup(pos);
}
} T2;
ll p[N], cnt = -1;
ll vis[N];
int main()
{
for (ll i = 2; i <= 300; i++)
{
bool flag = 1;
for (ll j = 2; j < i; j++)
if (i % j == 0)
flag = 0;

if (flag)
p[++cnt] = i, vis[cnt] = (1 - qpow(i, mod - 2, mod) + mod) % mod;
}

ll n = read(), m = read();
for (ll i = 1; i <= 4 * n; i++)
T2.sum[i] = T2.lazy[i] = 1;
for (ll i = 1; i <= n; i++)
{
ll x = read();
ll st = 0;
for (ll j = 0; j <= cnt; j++)
if (x % p[j] == 0)
st |= (1ll << j);
//cout << x << " " << st << endl;
T1.update(i, i, st, 1, 1, n);
T2.update(i, i, x, 1, 1, n);
}

for (ll t = 1; t <= m; t++)
{
char s[10];
scanf("%s", s);
//cout << "---" << endl;
if (s[0] == 'T')
{
ll l = read(), r = read();
ll ans = 1;
//cout << l << " " << r << endl;
ll st = T1.query(l, r, 1, 1, n);

for (ll i = 0; i <= cnt; i++)
if ((st & (1ll << i)))
ans = 1ll * ans * vis[i] % mod;

ans = 1ll * ans * T2.query(l, r, 1, 1, n) % mod;
printf("%d\n", ans);
}
else
{
ll l = read(), r = read(), x = read();
ll st = 0;
for (ll j = 0; j <= cnt; j++)
if (x % p[j] == 0)
st |= 1ll << j;
T1.update(l, r, st, 1, 1, n);
T2.update(l, r, x, 1, 1, n);
}
}
}