QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#369947 | #7782. Ursa Minor | 1234huang | TL | 3ms | 14828kb | C++20 | 4.3kb | 2024-03-28 19:55:24 | 2024-03-28 19:55:25 |
Judging History
answer
#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;
inline int read() {
int x = 0, f = 0; char ch = getchar();
while (ch < '0' or ch > '9') f |= (ch == '-'), ch = getchar();
while (ch >= '0' and ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
int __stk[128], __top;
inline void write(int x) {
if(x < 0) putchar('-'), x = -x;
do { __stk[++__top] = x % 10, x /= 10; } while (x);
while (__top) putchar(__stk[__top--] + '0');
}
const int mod = 998244353;
void Min(int &x, int y) { y < x and (x = y); }
void Max(int &x, int y) { y > x and (x = y); }
void inc(int &x, int y) { (x += y) >= mod and (x -= mod); }
void mul(int &x, int y) { x = 1ll * x * y % mod; }
int q_pow(int x, int k) { int res = 1; for (; k; k >>= 1, mul(x, x)) if (k & 1) mul(res, x); return res; }
bool stmer;
const int N = 2e5 + 10, M = 500, BL = 447;
const ull base = 127;
int n, m, q;
ull a[N], b[N], s[N];
namespace ST {
const int LG = 20;
int lg[N], st[LG][N];
void init() {
for (int i = 2; i <= m; i++) lg[i] = lg[i >> 1] + 1;
for (int i = 1; i < LG; i++) for (int j = 1; j + (1 << i) - 1 <= m; j++)
st[i][j] = __gcd(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
}
int ask(int l, int r) {
int h = lg[r - l + 1];
return __gcd(st[h][l], st[h][r - (1 << h) + 1]);
}
}
namespace Block1 {
ull S1[M][M], S2[M][M];
void init() {
for (int bl = 1; bl < BL; bl++) for (int i = 1; i <= n; i++) {
int id = i / BL; ull w = a[i] * b[i % bl];
S1[bl][id] += w, S2[bl][id] += (i % bl ? 0 : w);
}
}
void modify(int p, ull v) {
for (int bl = 1; bl < BL; bl++) {
int id = p / BL; ull w = (v - a[p]) * b[p % bl];
S1[bl][id] += w, S2[bl][id] += (p % bl ? 0 : w);
}
}
bool query(int l, int r, int k) {
int L = l / BL + 1, R = r / BL - 1; ull res = 0, s0 = 0, w;
for (int i = L; i <= R; i++) res += S1[k][i], s0 += S2[k][i];
while (l <= min(L * BL - 1 , r)) res += (w = a[l] * b[l % k]), s0 += (l++ % k ? 0 : w);
while (r >= max(R * BL + BL, l)) res += (w = a[r] * b[r % k]), s0 += (r-- % k ? 0 : w);
return res == s0 * s[k - 1];
}
}
namespace Block2 {
ull S1[M][M], S2[M];
void init() {
for (int i = 1; i <= n; i++) {
int id = i / BL;
S2[id] += (S1[id][i % BL] = a[i] * b[i]);
}
for (int i = 0; i <= n / BL; i++) {
for (int j = 1; j < BL; j++) S1[i][j] += S1[i][j - 1];
if (i) S2[i] += S2[i - 1];
}
}
void modify(int p, ull v) {
int id = p / BL; ull w = v * b[p] - a[p] * b[p];
for (int i = p % BL; i < BL; i++) S1[id][i] += w;
for (int i = id; i <= n / BL; i++) S2[i] += w;
}
ull ask(int l, int r) {
return S2[r / BL - 1] - S2[l / BL - 1] + S1[r / BL][r % BL] - (l % BL ? S1[l / BL][l % BL - 1] : 0);
}
bool query(int l, int r, int k) {
ull res = 0, s0 = 0;
while (l <= r) {
res = res * b[k] + ask(l, l + k - 1);
s0 += a[l], l += k;
}
return res == s0 * s[k - 1] * b[l - k];
}
}
bool edmer;
signed main() {
// freopen("gym104869F.in", "r", stdin);
// freopen("gym104869F.out", "w", stdout);
cerr << "[Memory] " << (&stmer - &edmer) / 1024 / 1024 << " MB\n";
n = read(), m = read(), q = read();
for (int i = 1; i <= n; i++) a[i] = read();
for (int i = 1; i <= m; i++) ST :: st[0][i] = read();
ST :: init(), b[0] = s[0] = 1;
for (int i = 1; i < N; i++) s[i] = s[i - 1] + (b[i] = b[i - 1] * base);
Block1 :: init(), Block2 :: init(), getchar();
while (q--) {
if (getchar() == 'U') {
int p = read(), v = read();
Block1 :: modify(p, v), Block2 :: modify(p, v), a[p] = v;
}
else {
int l = read(), r = read(), s = read(), t = read();
int k = __gcd(r - l + 1, ST :: ask(s, t));
if (k < BL) puts(Block1 :: query(l, r, k) ? "Yes" : "No");
else puts(Block2 :: query(l, r, k) ? "Yes" : "No");
}
}
cerr << "[Runtime] " << (double) clock() / CLOCKS_PER_SEC << " seconds\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 14828kb
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: 14100kb
input:
1 1 1 0 1 Q 1 1 1 1
output:
Yes
result:
ok "Yes"
Test #3:
score: -100
Time Limit Exceeded
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 Yes No Yes Yes No No No Yes Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes Yes No Yes Yes 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 Yes Yes Yes No Yes Yes Ye...