QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#404648 | #7782. Ursa Minor | -0x3F- | WA | 585ms | 30080kb | C++14 | 5.5kb | 2024-05-04 12:26:08 | 2024-05-04 12:26:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000000000000003;
inline long long qpow(long long a, long long b) {
long long s = 1;
while (b) {
if (b & 1) s = (__int128) s * a % mod;
a = (__int128) a * a % mod;
(b >>= 1);
}
return s;
}
const long long bas = 1145141919810;
const long long rbas = qpow(bas, mod - 2);
const long long _ = 2e5 + 10;
const long long B = 450;
long long lg[_], pw[_], rpw[_], spw[_];
inline long long gcd(long long x, long long y) {
while (y) {
long long z = x % y;
x = y;
y = z;
}
return x;
}
inline void init(long long n) {
pw[0] = rpw[0] = spw[0] = 1;
for (long long i = 1; i <= n; i++) {
pw[i] = (__int128) pw[i-1] * bas % mod;
rpw[i] = (__int128) rpw[i-1] * rbas % mod;
spw[i] = (spw[i-1] + pw[i]) % mod;
}
lg[1] = 0;
for (long long i = 2; i <= n; i++) {
lg[i] = lg[i-1] + (!(i & (i-1)));
}
}
long long n, arr[_];
struct node1 {
long long arr[_], brr[500];
inline void add(long long x, long long k) {
arr[x] = (arr[x] + k) % mod;
long long y = x / B;
brr[y] = (brr[y] + k) % mod;
}
inline long long query(long long l, long long r) {
long long L = l / B;
long long R = r / B;
long long ans = 0;
if (R - L >= 2) {
long long ll = (L+1) * B - 1;
long long rr = R * B;
for (long long i = l; i <= ll; i++) {
ans = (ans + arr[i]) % mod;
}
for (long long i = L+1; i <= R-1; i++) {
ans = (ans + brr[i]) % mod;
}
for (long long i = rr; i <= r; i++) {
ans = (ans + arr[i]) % mod;
}
} else {
for (long long i = l; i <= r; i++) {
ans = (ans + arr[i]) % mod;
}
}
return ans;
}
} num1[500], num2[500];
struct node2 {
long long arr[_], brr[500];
inline void add(long long x, long long k) {
long long l = x;
long long r = n;
long long L = l / B;
long long R = r / B;
if (R - L >= 2) {
long long ll = (L+1) * B - 1;
long long rr = R * B;
for (long long i = l; i <= ll; i++) {
arr[i] = (arr[i] + k) % mod;
}
for (long long i = L+1; i <= R-1; i++) {
brr[i] = (brr[i] + k) % mod;
}
for (long long i = rr; i <= r; i++) {
arr[i] = (arr[i] + k) % mod;
}
} else {
for (long long i = l; i <= r; i++) {
arr[i] = (arr[i] + k) % mod;
}
}
}
inline long long query(long long l, long long r) {
long long 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(long long x, long long k) {
long long diff = ((k - arr[x]) % mod + mod) % mod;
for (long long i = 1; i <= B; i++) {
num1[i].add(x, (__int128) diff * pw[x % i] % mod);
if (!(x % i)) num2[i].add(x, diff);
}
num3.add(x, (__int128) diff * pw[x] % mod);
arr[x] = k;
}
inline long long query(long long l, long long r, long long k) {
if (k <= B) {
return num1[k].query(l, r);
} else {
long long ans = 0;
for (long long i = l / k; i <= r / k; i++) {
long long L = max(l, i * k);
long long R = min(r, (i+1) * k - 1);
ans = (ans + (__int128) num3.query(L, R) * rpw[i * k]) % mod;
}
return ans;
}
}
inline long long tquery(long long l, long long r, long long k) {
if (k <= B) {
return num2[k].query(l, r);
} else {
long long ans = 0;
for (long long i = ((l+k-1) / k) * k; i <= r; i += k) {
ans = (ans + arr[i]) % mod;
}
return ans;
}
}
long long m, st[20][_];
inline long long calc(long long l, long long r) {
long long 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);
long long q;
cin >> n >> m >> q;
for (long long i = 1; i <= n; i++) {
long long x;
cin >> x;
modify(i, x);
}
for (long long i = 1; i <= m; i++) {
long long x;
cin >> x;
st[0][i] = x;
}
for (long long k = 1; k <= lg[n]; k++) {
for (long long 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': {
long long l, r, s, t;
cin >> l >> r >> s >> t;
long long k = gcd(r-l+1, calc(s, t));
long long sum = query(l, r, k);
long long tmp = tquery(l, r, k);
if (sum == (__int128) tmp * spw[k-1] % mod) {
cout << "Yes\n";
} else {
cout << "No\n";
}
break;
}
case 'U': {
long long p, v;
cin >> p >> v;
modify(p, v);
break;
}
}
}
cout << flush;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 13456kb
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: 4ms
memory: 13584kb
input:
1 1 1 0 1 Q 1 1 1 1
output:
Yes
result:
ok "Yes"
Test #3:
score: 0
Accepted
time: 585ms
memory: 30080kb
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: 345ms
memory: 14936kb
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: 315ms
memory: 14424kb
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'