QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#389904 | #7782. Ursa Minor | Mysterious_Cat | WA | 147ms | 15920kb | C++17 | 6.7kb | 2024-04-14 21:03:40 | 2024-04-14 21:03:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int S = 450;
const int N = 2e5 + 5;
const int base[2] = {3, 5};
const int mod[2] = {998244353, (int)1e9 + 7};
int n, m, q, B, lg[N], a[N], b[N], f[N][18], pw[N][2], inv[N][2], spw[N][2], bid[N], sum0[S][S][2], sum[S][S][2], Bsum[S][2], Sum[N][2];
int qpow(int x, int y, int p) {
int res = 1;
while (y) {
if (y & 1) {
res = 1ll * res * x % p;
}
x = 1ll * x * x % p;
y >>= 1;
}
return res;
}
int query(int l, int r) {
int k = lg[r - l + 1];
return __gcd(f[l][k], f[r - (1 << k) + 1][k]);
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> q;
B = sqrt(n);
for (int i = 2; i <= m; i++) lg[i] = lg[i / 2] + 1;
pw[0][0] = pw[0][1] = spw[0][0] = spw[0][1] = inv[0][0] = inv[0][1] = 1;
int iv[2] = {qpow(3, mod[0] - 2, mod[0]), qpow(5, mod[1] - 2, mod[1])};
for (int t = 0; t < 2; t++)
for (int i = 1; i <= n; i++) {
pw[i][t] = 1ll * pw[i - 1][t] * base[t] % mod[t];
inv[i][t] = 1ll * inv[i - 1][t] * iv[t] % mod[t];
spw[i][t] = (spw[i - 1][t] + pw[i][t]) % mod[t];
}
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= (n - 1) / B + 1; i++) {
int l = (i - 1) * B + 1, r = min(i * B, n);
bid[l] = i;
for (int t = 0; t < 2; t++) Sum[l][t] = 1ll * a[l] * pw[l][t] % mod[t];
for (int j = l + 1; j <= r; j++) {
bid[j] = i;
for (int t = 0; t < 2; t++) Sum[j][t] = (Sum[j - 1][t] + 1ll * a[j] * pw[j][t] % mod[t]) % mod[t];
}
for (int t = 0; t < 2; t++) Bsum[i][t] = (Bsum[i - 1][t] + Sum[r][t]) % mod[t];
for (int j = l; j <= r; j++)
for (int k = 1; k <= B; k++) {
for (int t = 0; t < 2; t++) {
sum[i][k][t] = (sum[i][k][t] + 1ll * a[j] * pw[j % k][t] % mod[t]) % mod[t];
sum0[i][k][t] = (sum0[i][k][t] + (j % k == 0 ? a[j] : 0)) % mod[t];
}
}
}
for (int i = 1; i <= m; i++) cin >> b[i], f[i][0] = b[i];
for (int j = 1; 1 << j <= m; j++)
for (int i = 1; i + (1 << j) - 1 <= m; i++)
f[i][j] = __gcd(f[i][j - 1], f[i + (1 << j - 1)][j - 1]);
for (int i = 1; i <= q; i++) {
char op;
cin >> op;
if (op == 'U') {
int x, v;
cin >> x >> v;
int l = (bid[x] - 1) * B + 1, r = min(bid[x] * B, n);
for (int k = 1; k <= B; k++)
for (int t = 0; t < 2; t++) {
sum[bid[x]][k][t] = (sum[bid[x]][k][t] - 1ll * a[x] * pw[x % k][t] % mod[t] + mod[t]) % mod[t];
sum0[bid[x]][k][t] = (sum0[bid[x]][k][t] - (x % k == 0 ? a[x] : 0) + mod[t]) % mod[t];
}
a[x] = v;
for (int k = 1; k <= B; k++)
for (int t = 0; t < 2; t++) {
sum[bid[x]][k][t] = (sum[bid[x]][k][t] + 1ll * a[x] * pw[x % k][t] % mod[t]) % mod[t];
sum0[bid[x]][k][t] = (sum0[bid[x]][k][t] + (x % k == 0 ? a[x] : 0)) % mod[t];
}
for (int t = 0; t < 2; t++) Sum[l][t] = 1ll * a[l] * pw[l][t] % mod[t];
for (int j = l + 1; j <= r; j++)
for (int t = 0; t < 2; t++)
Sum[j][t] = (Sum[j - 1][t] + 1ll * a[j] * pw[j][t] % mod[t]) % mod[t];
for (int j = 1; j <= (n - 1) / B + 1; j++)
for (int t = 0; t < 2; t++)
Bsum[j][t] = (Bsum[j - 1][t] + Sum[min(j * B, n)][t]) % mod[t];
}
else {
int l, r, s, t;
cin >> l >> r >> s >> t;
int g = __gcd(r - l + 1, query(s, t)), S[2] = {}, S0[2] = {};
if (g <= B) {
if (bid[l] == bid[r]) {
for (int j = l; j <= r; j++)
for (int t = 0; t < 2; t++) {
S[t] = (S[t] + 1ll * a[j] * pw[j % g][t] % mod[t]) % mod[t];
S0[t] = (S0[t] + (j % g == 0 ? a[j] : 0)) % mod[t];
}
}
else {
for (int j = 1; j < bid[r]; j++)
for (int t = 0; t < 2; t++) {
S[t] = (S[t] + sum[j][g][t]) % mod[t];
S0[t] = (S0[t] + sum0[j][g][t]) % mod[t];
}
for (int j = (bid[r] - 1) * B + 1; j <= r; j++)
for (int t = 0; t < 2; t++) {
S[t] = (S[t] + 1ll * a[j] * pw[j % g][t] % mod[t] + mod[t]) % mod[t];
S0[t] = (S0[t] + (j % g == 0 ? a[j] : 0)) % mod[t];
}
for (int j = 1; j < bid[l]; j++)
for (int t = 0; t < 2; t++) {
S[t] = (S[t] + sum[j][g][t]) % mod[t];
S0[t] = (S0[t] - sum0[j][g][t] + mod[t]) % mod[t];
}
for (int j = (bid[l] - 1) * B + 1; j < l; j++)
for (int t = 0; t < 2; t++) {
S[t] = (S[t] - 1ll * a[j] * pw[j % g][t] % mod[t] + mod[t]) % mod[t];
S0[t] = (S0[t] - (j % g == 0 ? a[j] : 0) + mod[t]) % mod[t];
}
}
}
else {
for (int j = g * ((l - 1) / g + 1); j <= r; j += g)
for (int t = 0; t < 2; t++) S0[t] = (S0[t] + a[j]) % mod[t];
for (int j = 0; j <= r; j += g) {
if (j > n) break;
int L = j + !j, R = min(j + g - 1, r);
for (int t = 0; t < 2; t++) {
int v = Bsum[bid[R] - 1][t] + Sum[R][t] - (Bsum[bid[L - 1] - 1][t] + Sum[L - 1][t]);
v = (v % mod[t] + mod[t]) % mod[t];
S[t] = (S[t] + 1ll * v * inv[j][t] % mod[t]) % mod[t];
}
}
for (int j = 0; j < l; j += g) {
int L = j + !j, R = min(j + g - 1, l - 1);
for (int t = 0; t < 2; t++) {
int v = Bsum[bid[R] - 1][t] + Sum[R][t] - (Bsum[bid[L - 1] - 1][t] + Sum[L - 1][t]);
v = (v % mod[t] + mod[t]) % mod[t];
S[t] = (S[t] - 1ll * v * inv[j][t] % mod[t] + mod[t]) % mod[t];
}
}
}
if (S[0] == 1ll * S0[0] * spw[g - 1][0] % mod[0]
&& S[1] == 1ll * S0[1] * spw[g - 1][1] % mod[1]) cout << "Yes\n";
else cout << "No\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11908kb
input:
6 4 5 1 1 4 5 1 4 3 3 2 4 Q 1 5 1 2 Q 2 5 3 4 U 5 2 Q 1 6 1 2 Q 2 5 3 4
output:
Yes No No Yes
result:
ok 4 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 15920kb
input:
1 1 1 0 1 Q 1 1 1 1
output:
Yes
result:
ok "Yes"
Test #3:
score: -100
Wrong Answer
time: 147ms
memory: 12252kb
input:
2000 2000 200000 1 1 2 0 0 2 0 2 0 0 0 0 0 2 2 1 2 0 0 2 2 2 1 0 1 2 1 2 0 0 1 1 1 2 0 0 2 2 2 2 0 2 0 0 2 1 2 0 0 1 2 2 1 0 2 0 0 0 1 2 2 1 2 2 0 0 1 1 1 0 0 2 0 0 1 1 0 2 2 2 1 0 0 1 0 1 2 2 2 1 1 2 2 1 2 1 0 2 2 3 1 3 2 3 1 0 1 2 0 1 1 1 0 2 2 3 2 0 3 2 3 3 1 2 3 1 2 0 1 0 3 1 0 0 2 0 1 2 1 3 2 2...
output:
Yes Yes No No Yes No No No Yes Yes Yes No Yes Yes Yes No No Yes Yes Yes Yes Yes Yes No Yes No Yes No Yes Yes No No No No No Yes No No No Yes Yes No Yes No Yes Yes Yes Yes Yes Yes Yes Yes Yes No Yes Yes No Yes Yes Yes No No Yes No Yes No No No Yes Yes Yes Yes Yes Yes No Yes Yes No No Yes Yes No Yes Y...
result:
wrong answer 4th words differ - expected: 'Yes', found: 'No'