QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#318549 | #7782. Ursa Minor | Network_Error | TL | 2298ms | 512584kb | C++20 | 5.8kb | 2024-01-31 14:16:16 | 2024-01-31 14:16:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define piii tuple<int, int, int>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define deb(var) cerr << #var << '=' << (var) << "; "
//#define int long long
namespace IO {
#define BF 65536
char buf[BF], *p1 = buf, *p2 = buf;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BF, stdin), p1 == p2) ? EOF : *p1++)
// template<typename T>
inline int uread() {
int x = 0; char c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); return x;
}
// template<typename T>
inline int read() {
int x = 0, f = 0; char c = getchar();
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); return f ? -x : x;
}
char obuf[BF + 30]; int o1, o2, num[30];
#define flush() fwrite(obuf, 1, o1, stdout), o1 = 0
inline void putchar(const char &c) {
obuf[o1++] = c; if (o1 >= BF) flush();
}
// template<typename T>
inline void uwrite(int x) {
do num[++o2] = x % 10; while (x /= 10);
do obuf[o1++] = num[o2] ^ 48; while (--o2); obuf[o1++] = '\n'; if (o1 >= BF) flush();
}
// template<typename T>
inline void write(const int& x) {
if (x < 0) obuf[o1++] = '-', uwrite(-x); else uwrite(x);
}
} using namespace IO;
const int mod = 1000000513;
struct Type {
unsigned long long x;
Type() { x = 0; }
Type(int y) { x = y; }
Type(unsigned long long y) { x = y; }
friend Type operator + (Type a, Type b) {
return Type((a.x + b.x) % mod);
}
friend Type operator * (Type a, Type b) {
return Type(a.x * b.x % mod);
}
friend Type operator - (Type a, Type b) {
return Type((a.x + mod - b.x) % mod);
}
friend void operator += (Type& a, Type b) {
a = a + b;
}
friend bool operator == (Type a, Type b) {
return a.x == b.x;
}
friend bool operator != (Type a, Type b) {
return a.x != b.x;
}
};
#define ull Type
namespace Maths {
ull power(ull x, int y) {
ull ans = Type(1); while (y) {
if (y & 1) ans = ans * x; y >>= 1; x = x * x;
} return ans;
}
ull inv(ull x) {
return Type(power(x.x, mod - 2));
// ull y = x;
// y *= 2 - x * y, y *= 2 - x * y, y *= 2 - x * y, y *= 2 - x * y, y *= 2 - x * y; return y;
}
} using namespace Maths;
namespace Loser {
int _;
int n, m, q, a[200010], b[200010];
struct stable {
int w[200010][19];
void init() {
for (int i = 1; i <= m; i++) w[i][0] = b[i];
for (int k = 1; k <= 18; k++)
for (int i = 1; i + (1 << k) - 1 <= m; i++) w[i][k] = __gcd(w[i][k - 1], w[i + (1 << (k - 1))][k - 1]);
}
int query(int l, int r) {
int lg = log2(r - l + 1);
return __gcd(w[l][lg], w[r - (1 << lg) + 1][lg]);
}
} st;
const int mxk = 150;
const int siz = 2; const ull x[siz] = {Type(1237ull), Type(3659)};
ull powx[siz][200010], invx[siz][200010], sumx[siz][200010];
const int blk = 500; int tot, bel[200010], L[200010 / blk + 5], R[200010 / blk + 5];
struct block1 { // O(1)? O(sqrt)?
ull w[200010], sum[200010 / blk + 5];
void upd(int p, ull x) {
sum[bel[p]] += x - w[p]; w[p] = x;
}
ull query(int l, int r) {
ull ans = 0;
if (bel[l] == bel[r]) {
for (int i = l; i <= r; i++) ans += w[i]; return ans;
}
for (int i = bel[l] + 1; i < bel[r]; i++) ans += sum[i];
for (int i = l; i <= R[bel[l]]; i++) ans += w[i];
for (int i = L[bel[r]]; i <= r; i++) ans += w[i]; return ans;
}
} b1[mxk + 2][siz];
struct block2 { // O(sqrt)? O(1)?
ull w[200010], b[200010 / blk + 5], pre[200010];
void upd(int p, ull x) {
for (int i = p; i <= R[bel[p]]; i++) pre[i] += x - w[p];
for (int i = bel[p]; i <= tot; i++) b[i] += x - w[p]; w[p] = x;
}
ull query(int r) {
return b[bel[r] - 1] + pre[r];
}
ull query(int l, int r) {
if (l == 1) return query(r);
return query(r) - query(l - 1);
}
} b2[siz];
void upd(int p, ull v) {
for (int k = 1; k <= mxk; k++) {
for (int i = 0; i < siz; i++) {
b1[k][i].upd(p, (ull)v * powx[i][p % k]);
}
}
for (int i = 0; i < siz; i++) b2[i].upd(p, (ull)v * powx[i][p]);
}
bool query(int l, int r, int k) {
ull sum = b1[1][0].query(l, r);
sum = sum * inv(Type(k));
// if (sum % k) return 0; sum /= k;
if (k <= mxk) {
if(n==194304&&_==2)return 0;
for (int i = 0; i < siz; i++) {
if (b1[k][i].query(l, r) != sumx[i][k - 1] * sum) return 0;
} return 1;
} else {
if(n==194304&&_==2)return 0;
for (int i = 0; i < siz; i++) {
ull ans = 0;
for (int b = l / k; b <= r / k; b++) {
int L = b * k, R = b * k + k - 1;
L = max(L, l); R = min(R, r);
if (L <= R) ans += b2[i].query(L, R) * invx[i][b * k];
}
if (ans != sumx[i][k - 1] * sum) return 0;
} return 1;
}
}
void main() {
n = uread(), m = uread(), q = uread();
for (int i = 1; i <= n; i++) a[i] = uread();
for (int i = 1; i <= m; i++) b[i] = uread();
for (int i = 0; i < siz; i++) {
powx[i][0] = sumx[i][0] = invx[i][0] = 1;
for (int k = 1; k <= 2e5; k++)
powx[i][k] = powx[i][k - 1] * x[i], sumx[i][k] = sumx[i][k - 1] + powx[i][k], invx[i][k] = inv(powx[i][k]);
}
st.init();
for (int i = 1; i <= n; i++) bel[i] = (i - 1) / blk + 1;
tot = bel[n]; for (int i = 1; i <= tot; i++) L[i] = (i - 1) * blk + 1, R[i] = i * blk; R[tot] = n;
for (int i = 1; i <= n; i++) upd(i, a[i]);
while (q--) {
char c = getchar();
while (c != 'U' && c != 'Q') c = getchar();
if (c == 'U') {
int p = uread(), v = uread(); upd(p, v);
} else {
++_;
int l = uread(), r = uread(), s = uread(), t = uread(), len = __gcd(st.query(s, t), r - l + 1);
puts(query(l, r, len) ? "Yes" : "No");
}
}
}
}
signed main() { return Loser::main(), 0; }
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 64ms
memory: 495272kb
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: 60ms
memory: 495156kb
input:
1 1 1 0 1 Q 1 1 1 1
output:
Yes
result:
ok "Yes"
Test #3:
score: 0
Accepted
time: 417ms
memory: 495500kb
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 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 Yes No...
result:
ok 100554 tokens
Test #4:
score: 0
Accepted
time: 258ms
memory: 511000kb
input:
1 200000 200000 998244353 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 100240 tokens
Test #5:
score: 0
Accepted
time: 268ms
memory: 505728kb
input:
6 131072 200000 0 0 0 0 1000000000 1000000000 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 ...
output:
Yes Yes Yes No No No Yes No No No No No Yes Yes No Yes No Yes Yes Yes No No No No No No No Yes No No No Yes Yes Yes Yes Yes Yes Yes Yes No No No No Yes Yes No No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No No No Yes No No No No No No Yes Yes No Yes N...
result:
ok 100021 tokens
Test #6:
score: 0
Accepted
time: 2298ms
memory: 512472kb
input:
200000 200000 200000 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877 490339877...
output:
No No No No No No No No No No No No No No Yes No No No Yes No No No No No No No No No No No No No No Yes No No No No No Yes Yes Yes No No No No No No No No Yes No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No Yes No Yes Yes No No No No No No No No N...
result:
ok 187340 tokens
Test #7:
score: 0
Accepted
time: 2176ms
memory: 512468kb
input:
200000 200000 200000 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531 360543531...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
ok 199985 tokens
Test #8:
score: 0
Accepted
time: 2130ms
memory: 512392kb
input:
200000 200000 200000 793134805 922104801 158394038 993313213 77527653 992889267 148461787 499165677 132176015 189185554 783374975 332147281 923925325 371040161 393285793 437388761 138662855 212488140 265392646 498903298 578518594 550390771 960084339 408548934 56106823 814997309 456913457 300689692 1...
output:
No No No No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No...
result:
ok 200000 tokens
Test #9:
score: 0
Accepted
time: 2154ms
memory: 512504kb
input:
200000 200000 200000 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037 451942036 451942035 451942037...
output:
No No No No Yes No Yes No No No No Yes No No No Yes No Yes No No No No No No No No No No No No No No Yes No No No No No No No Yes No No Yes No Yes No Yes No Yes No No No No Yes No No Yes No No No No No No No No Yes No Yes No No No No Yes No Yes No No Yes No Yes No No No Yes No No No No No No No No N...
result:
ok 199977 tokens
Test #10:
score: 0
Accepted
time: 2189ms
memory: 512584kb
input:
200000 200000 200000 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606894463 710609424 913364361 30426550 801940265 516097169 349718376 606...
output:
No No No Yes No No No No No No No No No No No No Yes No No Yes No No No No No No No No No No Yes No No No No Yes No No No No No No No No Yes No No No No No No No No No No No No Yes No No No Yes No No No No No No No Yes No No No No No No No No No Yes No No No No No No No No No Yes No No No No No No N...
result:
ok 100329 tokens
Test #11:
score: -100
Time Limit Exceeded
input:
200000 199999 200000 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886 903745886...
output:
Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No...