QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#404646 | #7782. Ursa Minor | -0x3F- | WA | 374ms | 19112kb | C++14 | 4.8kb | 2024-05-04 12:21:34 | 2024-05-04 12:21:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int bas = 114514;
const int rbas = 137043501;
const int _ = 2e5 + 10;
const int B = 450;
int lg[_], pw[_], rpw[_], spw[_];
inline int gcd(int x, int y) {
while (y) {
int z = x % y;
x = y;
y = z;
}
return x;
}
inline void init(int n) {
pw[0] = rpw[0] = spw[0] = 1;
for (int i = 1; i <= n; i++) {
pw[i] = (long long) pw[i-1] * bas % mod;
rpw[i] = (long long) rpw[i-1] * rbas % mod;
spw[i] = (spw[i-1] + pw[i]) % mod;
}
lg[1] = 0;
for (int i = 2; i <= n; i++) {
lg[i] = lg[i-1] + (!(i & (i-1)));
}
}
int n, arr[_];
struct node1 {
int arr[_], brr[500];
inline void add(int x, int k) {
arr[x] = (arr[x] + k) % mod;
int y = x / B;
brr[y] = (brr[y] + k) % mod;
}
inline int query(int l, int r) {
int L = l / B;
int R = r / B;
int ans = 0;
if (R - L >= 2) {
int ll = (L+1) * B - 1;
int rr = R * B;
for (int i = l; i <= ll; i++) {
ans = (ans + arr[i]) % mod;
}
for (int i = L+1; i <= R-1; i++) {
ans = (ans + brr[i]) % mod;
}
for (int i = rr; i <= r; i++) {
ans = (ans + arr[i]) % mod;
}
} else {
for (int i = l; i <= r; i++) {
ans = (ans + arr[i]) % mod;
}
}
return ans;
}
} num1[500], num2[500];
struct node2 {
int arr[_], brr[500];
inline void add(int x, int k) {
int l = x;
int r = n;
int L = l / B;
int R = r / B;
if (R - L >= 2) {
int ll = (L+1) * B - 1;
int rr = R * B;
for (int i = l; i <= ll; i++) {
arr[i] = (arr[i] + k) % mod;
}
for (int i = L+1; i <= R-1; i++) {
brr[i] = (brr[i] + k) % mod;
}
for (int i = rr; i <= r; i++) {
arr[i] = (arr[i] + k) % mod;
}
} else {
for (int i = l; i <= r; i++) {
arr[i] = (arr[i] + k) % mod;
}
}
}
inline int query(int l, int r) {
int ans = (arr[r] + brr[r / B]) % mod;
if (l != 1) {
ans = ((ans - arr[l-1] - brr[(l-1) / B]) % mod + mod) % mod;
}
return ans;
}
} num3;
inline void modify(int x, int k) {
int diff = ((k - arr[x]) % mod + mod) % mod;
for (int i = 1; i <= B; i++) {
num1[i].add(x, (long long) diff * pw[x % i] % mod);
if (!(x % i)) num2[i].add(x, diff);
}
num3.add(x, (long long) diff * pw[x] % mod);
arr[x] = k;
}
inline int query(int l, int r, int k) {
if (k <= B) {
return num1[k].query(l, r);
} else {
int ans = 0;
for (int i = l / k; i <= r / k; i++) {
int L = max(l, i * k);
int R = min(r, (i+1) * k - 1);
ans = (ans + (long long) num3.query(L, R) * rpw[i * k]) % mod;
}
return ans;
}
}
inline int tquery(int l, int r, int k) {
if (k <= B) {
return num2[k].query(l, r);
} else {
int ans = 0;
for (int i = ((l+k-1) / k) * k; i <= r; i += k) {
ans = (ans + arr[i]) % mod;
}
return ans;
}
}
int m, st[20][_];
inline int calc(int l, int r) {
int k = lg[r - l + 1];
return gcd(st[k][l], st[k][r-(1<<k)+1]);
}
int main() {
init(200000);
ios::sync_with_stdio(0);
cin.tie(0);
int q;
cin >> n >> m >> q;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
modify(i, x);
}
for (int i = 1; i <= m; i++) {
int x;
cin >> x;
st[0][i] = x;
}
for (int k = 1; k <= lg[n]; k++) {
for (int i = 1; i <= n - (1 << k) + 1; i++) {
st[k][i] = gcd(st[k-1][i], st[k-1][i+(1<<(k-1))]);
}
}
while (q--) {
char ch;
cin >> ch;
switch (ch) {
case 'Q': {
int l, r, s, t;
cin >> l >> r >> s >> t;
int k = gcd(r-l+1, calc(s, t));
int sum = query(l, r, k);
int tmp = tquery(l, r, k);
if (sum == (long long) tmp * spw[k-1] % mod) {
cout << "Yes\n";
} else {
cout << "No\n";
}
break;
}
case 'U': {
int p, v;
cin >> p >> v;
modify(p, v);
break;
}
}
}
cout << flush;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 9368kb
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: 2ms
memory: 9344kb
input:
1 1 1 0 1 Q 1 1 1 1
output:
Yes
result:
ok "Yes"
Test #3:
score: 0
Accepted
time: 374ms
memory: 19112kb
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: 272ms
memory: 10204kb
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: -100
Wrong Answer
time: 253ms
memory: 9932kb
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:
No No No 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 No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No 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:
wrong answer 1st words differ - expected: 'Yes', found: 'No'