QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#386731 | #7782. Ursa Minor | A_programmer | WA | 2690ms | 307096kb | C++17 | 4.5kb | 2024-04-11 19:42:32 | 2024-04-11 19:42:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 200904101;
const ll Base = 113131;
const int B = 455;
const int maxn = 2e5 + 5;
int a[maxn], b[maxn], f[maxn][18], lg[maxn];
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int query(int l, int r)
{
int k = lg[r - l + 1];
return gcd(f[l][k], f[r - (1 << k) + 1][k]);
}
ll fpow(ll a, ll b)
{
ll ans = 1;
while (b)
{
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
ll mi[maxn], inv[maxn], pre[maxn], iBase;
int bs, bn, bl[maxn], br[maxn], bel[maxn];
struct ds1 // O(1) query to O(sqrt(n)) update a_i * x^i
{
ll c[maxn], tag[maxn];
void add(int pos, ll x)
{
for (int i = pos; i <= br[bel[pos]]; i++) (c[i] += x) %= mod;
for (int i = bel[pos] + 1; i <= bn; i++) (tag[i] += x) %= mod;
}
ll sum(int pos) { return (c[pos] + tag[bel[pos]]) % mod; }
}ds1;
struct ds2 // O(sqrt(n)) query to O(1) update a_i * x^(i % k)
{
int c[maxn], sum[30005], sud[30005];
vector<int> d;
void add(int pos, int x) { (c[pos] += x) %= mod; (sum[bel[pos]] += x) %= mod; }
void addD(int pos, int x) { (d[pos] += x) %= mod; (sud[bel[pos]] += x) %= mod; }
ll sumP(int pos)
{
int ans = 0;
for (int i = 1; i < bel[pos]; i++) (ans += sum[i]) %= mod;
for (int i = bl[bel[pos]]; i <= pos; i++) (ans += c[i]) %= mod;
return ans;
}
ll sumD(int pos)
{
int ans = 0;
for (int i = 1; i < bel[pos]; i++) (ans += sud[i]) %= mod;
for (int i = bl[bel[pos]]; i <= pos; i++) (ans += d[i]) %= mod;
return ans;
}
}ds2[B];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
mi[0] = inv[0] = pre[0] = 1; iBase = fpow(Base, mod - 2);
for (int i = 1; i <= n; i++) mi[i] = mi[i - 1] * Base % mod, pre[i] = (pre[i - 1] + mi[i]) % mod;
for (int i = 1; i <= n; i++) inv[i] = inv[i - 1] * iBase % mod;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1, k = 0; i <= m; i++)
{
cin >> b[i], f[i][0] = b[i];
lg[i] = k;
if (i == (1 << (k + 1))) lg[i] = ++k;
}
for (int j = 1; j <= 17; 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]);
bs = max(1, (int)(sqrt(n) - 100));
for (int i = 1; i <= n; i += bs)
bl[++bn] = i, br[bn] = i + bs - 1;
br[bn] = n;
for (int i = 1; i <= bn; i++)
for (int j = bl[i]; j <= br[i]; j++) bel[j] = i;
for (int j = 1; j <= bs; j++) ds2[j].d.resize(n / j + 1);
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= bs; j++)
{
ds2[j].add(i, a[i] * mi[i % j] % mod);
if (i % j == 0) ds2[j].addD(i / j, a[i]);
}
ds1.add(i, a[i] * mi[i] % mod);
}
while (q--)
{
char s[4];
cin >> s;
if (s[0] == 'U')
{
int pos;
ll v;
cin >> pos >> v;
v = (v + mod - a[pos]) % mod;
for (int i = 1; i <= bs; i++)
{
ds2[i].add(pos, v * mi[pos % i] % mod);
if (pos % i == 0) ds2[i].addD(pos / i, v);
}
ds1.add(pos, v * mi[pos] % mod);
(a[pos] += v) %= mod;
}
else
{
int l, r, s, t;
cin >> l >> r >> s >> t;
int k = gcd(r - l + 1, query(s, t));
ll hsh = 0, hs2 = 0;
if (k <= bs)
{
hsh = ds2[k].sumP(r) - ds2[k].sumP(l - 1);
hs2 = ds2[k].sumD(r / k) - ds2[k].sumD((l - 1) / k);
if (hsh < 0) hsh += mod;
if (hs2 < 0) hs2 += mod;
}
else
{
for (int i = l; i <= r; i += k) (hs2 += a[i]) %= mod;
for (int i = l / k; i <= r / k; i++)
{
int L = i * k, R = L + k - 1;
L = max(L, l), R = min(R, r);
if (L > R) continue;
ll res = (ds1.sum(R) + mod - ds1.sum(L - 1)) * inv[i * k] % mod;
(hsh += res) %= mod;
}
}
(hs2 *= pre[k - 1]) %= mod;
cout << (hsh == hs2 ? "Yes\n" : "No\n");
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5596kb
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: 1ms
memory: 5532kb
input:
1 1 1 0 1 Q 1 1 1 1
output:
Yes
result:
ok "Yes"
Test #3:
score: 0
Accepted
time: 1010ms
memory: 5724kb
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: 61ms
memory: 21156kb
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: 43ms
memory: 15752kb
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: 1857ms
memory: 306968kb
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: 1687ms
memory: 307008kb
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: 1615ms
memory: 307052kb
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: 1667ms
memory: 307008kb
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: 1712ms
memory: 307056kb
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: 0
Accepted
time: 2690ms
memory: 307096kb
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...
result:
ok 100000 tokens
Test #12:
score: 0
Accepted
time: 2567ms
memory: 306936kb
input:
199997 199989 199999 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047 516381047...
output:
Yes Yes No No No No No No Yes No No No No No Yes No Yes No Yes No No Yes No No No No No No No No Yes No No No No Yes No Yes No Yes Yes Yes No Yes No No No No No No Yes Yes Yes Yes Yes No Yes No No No Yes Yes No No No No No No No No No No Yes Yes No No No No Yes Yes No Yes No No No No No No No Yes No...
result:
ok 100000 tokens
Test #13:
score: 0
Accepted
time: 2643ms
memory: 306900kb
input:
200000 199899 200000 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100 738568100...
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...
result:
ok 100000 tokens
Test #14:
score: 0
Accepted
time: 2377ms
memory: 306932kb
input:
200000 199990 200000 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491 748167491...
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...
result:
ok 100000 tokens
Test #15:
score: 0
Accepted
time: 1006ms
memory: 307008kb
input:
200000 200000 200000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000...
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 200000 tokens
Test #16:
score: 0
Accepted
time: 1006ms
memory: 307008kb
input:
200000 200000 200000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000...
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 200000 tokens
Test #17:
score: 0
Accepted
time: 1777ms
memory: 306932kb
input:
200000 200000 200000 136241709 121069654 74104428 402269028 289305416 855066384 59173243 188019353 669781180 986996513 504339812 329791320 25125974 222565943 288337442 964609791 466878029 264002600 189175389 9157365 469615339 896075603 753652692 122288279 240727003 784469217 906985969 890794301 2169...
output:
result:
ok 0 tokens
Test #18:
score: 0
Accepted
time: 1252ms
memory: 306984kb
input:
200000 200000 200000 273240622 378627620 579491720 693306037 632472065 511340335 670989889 554488479 652467925 278524470 836147563 424777678 759339952 855362660 230757613 865543002 560326470 755302163 785969817 6168093 585297358 945522008 799833815 740595138 24393108 602846463 227643614 845760733 81...
output:
result:
ok 0 tokens
Test #19:
score: 0
Accepted
time: 1464ms
memory: 306940kb
input:
200000 200000 200000 902784461 118694875 998774623 411874728 685597851 368044897 72498166 42228570 960589282 760858636 63223215 20140256 256927497 432494553 374529608 902188891 898994 969710880 697644219 743838599 684197754 515142816 492082738 409457048 326043554 219156706 376310102 878117528 358651...
output:
result:
ok 0 tokens
Test #20:
score: -100
Wrong Answer
time: 2548ms
memory: 307008kb
input:
200000 200000 200000 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584 658243584...
output:
Yes No Yes No Yes No No No Yes No No No No No No No Yes No Yes Yes No No Yes No No No No No Yes Yes No No No No Yes No Yes No Yes No Yes No Yes No No No No No No No Yes No No No No No Yes No No No Yes No Yes No Yes No Yes No Yes No No No No No Yes No No No No Yes Yes No Yes No Yes No Yes No No No Ye...
result:
wrong answer 1402nd words differ - expected: 'Yes', found: 'No'