QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#386833 | #7782. Ursa Minor | SamponYW | WA | 1384ms | 343644kb | C++14 | 4.6kb | 2024-04-11 20:32:41 | 2024-04-11 20:32:42 |
Judging History
answer
#include <bits/stdc++.h>
#define db double
#define il inline
#define re register
#define ll long long
#define ui unsigned
#define ull ui ll
#define i128 __int128
#define pii pair<int, int>
#define fi first
#define se second
#define eb emplace_back
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define mems(v, x) memset(v, x, sizeof(v))
#define memc(a, b) memcpy(a, b, sizeof(a))
#define FOR(i, L, R) for(re int i = (L); i <= (R); ++i)
#define ROF(i, R, L) for(re int i = (R); i >= (L); --i)
#define LS i << 1, l, mid
#define RS i << 1 | 1, mid + 1, r
#define popc(x) __builtin_popcount(x)
using namespace std;
#define N 200005
const int B = 200;
#define P1 1000000007
#define P2 1000000009
int be[N], L[N], R[N];
int pw1[N], pw2[N];
int n, m, q, a[N], b[N], c[N];
struct H {
int v1, v2;
il void init(int k, int c) {
v1 = (1ll * pw1[k] * c % P1 + P1) % P1;
v2 = (1ll * pw2[k] * c % P2 + P2) % P2;
}
il H operator = (const int &v) {
v1 = (v + P1) % P1, v2 = (v + P2) % P2; return *this;
}
il H operator + (const H &b) const {
return {(v1 + b.v1) % P1, (v2 + b.v2) % P2};
}
il H operator += (const H &b) {
(v1 += b.v1) %= P1, (v2 += b.v2) %= P2; return *this;
}
il H operator * (const int &v) const {
return {1ll * v1 * v % P1, 1ll * v2 * v % P2};
}
} ;
struct sma {
int B; H v[N], s[N];
il void build(int k) {
B = k;
FOR(i, 1, n) {
v[i].init(i % B, c[i]);
s[be[i]] += v[i];
}
}
il void upd(int x, int k) {
H t; t.init(x % B, k);
v[x] += t, s[be[x]] += t;
}
il H query(int l, int r) {
int a = be[l], b = be[r]; H ns = {0, 0};
if(a == b) {FOR(i, l, r) ns += v[i]; return ns;}
FOR(i, l, R[a]) ns += v[i];
FOR(i, a + 1, b - 1) ns += s[i];
FOR(i, L[b], r) ns += v[i];
return ns;
}
} T[B + 5];
struct info {
H v; int L;
} v[N], s[N], pre[N], suf[N];
il H mult(int k, H v) {
(v.v1 += P1) %= P1, (v.v2 += P2) %= P2;
return {1ll * pw1[k] * v.v1 % P1, 1ll * pw2[k] * v.v2 % P2};
}
il info merge(info A, info B) {
return {A.v + mult(A.L, B.v), A.L + B.L};
}
namespace big {
il void reb(int t) {
info k = {{0, 0}, 0};
FOR(i, L[t], R[t])
k = merge(k, v[i]), pre[i] = k;
s[t] = k, k = {{0, 0}, 0};
ROF(i, R[t], L[t])
k = merge(v[i], k), suf[i] = k;
}
il void build() {
FOR(i, 1, n) v[i] = {c[i], 1};
FOR(i, 1, be[n]) reb(i);
}
il void upd(int x, int k) {v[x].v += {(k % P1 + P1) % P1, (k % P2 + P2) % P2}, reb(be[x]);}
il info query(int l, int r) {
if(l > r) return {{0, 0}, 0}; info k = {{0, 0}, 0};
if(be[l] == be[r]) {
FOR(i, l, r) k = merge(k, v[i]); return k;}
k = merge(k, suf[l]);
FOR(i, be[l] + 1, be[r] - 1) k = merge(k, s[i]);
k = merge(k, pre[r]); return k;
}
}
il void upd(int x, int k) {
int d = k - c[x]; c[x] = k;
FOR(i, 1, B) T[i].upd(x, d); big::upd(x, d);
}
namespace rmq {
int st[20][N];
il void build() {
FOR(i, 1, m) st[0][i] = b[i];
FOR(i, 1, 19) FOR(j, 1, m - (1 << i) + 1)
st[i][j] = __gcd(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
}
il int query(int l, int r) {
int t = __lg(r - l + 1);
return __gcd(st[t][l], st[t][r - (1 << t) + 1]);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m >> q;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, n) c[i] = a[i % n + 1] - a[i];
FOR(i, 1, m) cin >> b[i]; rmq::build();
pw1[0] = 1; FOR(i, 1, n) pw1[i] = 19260817ll * pw1[i - 1] % P1;
pw2[0] = 1; FOR(i, 1, n) pw2[i] = 19260817ll * pw2[i - 1] % P2;
FOR(i, 1, n) {
be[i] = (i - 1) / B + 1, R[be[i]] = i;
if(be[i] != be[i - 1]) L[be[i]] = i;
}
FOR(i, 1, B) T[i].build(i); big::build();
while(q--) {
char op; cin >> op;
if(op == 'U') {
int x, v; cin >> x >> v, a[x] = v;
upd(x, a[x % n + 1] - a[x]);
--x; if(!x) x = n;
upd(x, a[x % n + 1] - a[x]);
}
else {
int l, r, s, t; cin >> l >> r >> s >> t;
if(l == r) {cout << "Yes\n"; continue;}
int g = __gcd(r - l + 1, rmq::query(s, t)); H ns = {0, 0};
if(g <= B) ns = T[g].query(l, r - 1) + mult(r % g, {(a[l] + P1 - a[r]) % P1, (a[l] + P2 - a[r]) % P2});
else {
int L = l;
while(L + g - 1 <= r - 1) {
auto k = big::query(L, L + g - 1);
ns += k.v, L += g;
}
auto k = big::query(L, r - 1);
k = merge(k, {{(a[l] + P1 - a[r]) % P1, (a[l] + P2 - a[r]) % P2}, 1}), ns += k.v;
}
if(!ns.v1 && !ns.v2) cout << "Yes\n"; else cout << "No\n";
}
}
cerr << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5696kb
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: 5580kb
input:
1 1 1 0 1 Q 1 1 1 1
output:
Yes
result:
ok "Yes"
Test #3:
score: 0
Accepted
time: 1384ms
memory: 9068kb
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: 554ms
memory: 19488kb
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: 589ms
memory: 14416kb
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: -100
Wrong Answer
time: 1300ms
memory: 343644kb
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:
wrong answer 756th words differ - expected: 'Yes', found: 'No'