QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#347618 | #8338. Quad Kingdoms Chess | ucup-team2279# | WA | 32ms | 17512kb | C++14 | 3.1kb | 2024-03-09 14:32:59 | 2024-03-09 14:33:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define sz(a) int((a).size())
template<class T> void cmin(T &a, const T &b) {if (a > b) a = b;}
template<class T> void cmax(T &a, const T &b) {if (a < b) a = b;}
using LL = long long;
const int N = 1e5 + 5;
const int B1 = 19260817, P1 = 998244353;
const int B2 = 19491001, P2 = 1e9 + 7;
// const int B1 = 10, P1 = 998244353;
// const int B2 = 10, P2 = 1e9 + 7;
inline int qp(int a, int b, int P) {
int res = 1;
while (b) {
if (b & 1) res = LL(res) * a % P;
a = LL(a) * a % P;
b /= 2;
}
return res;
}
int pw1[N], ipw1[N], iB1;
int pw2[N], ipw2[N], iB2;
struct SGT {
int n;
int a[N];
void init() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
build(1, 1, n);
}
int mx[4 * N], cnt[4 * N];
int has1[4 * N], has2[4 * N];
#define ls(i) (2 * i)
#define rs(i) (2 * i + 1)
tuple<int, int, int> calc(int i, int l, int r, int Mx, int ct) {
if (l == r) {
if (mx[i] >= Mx) return {1, LL(a[l]) * pw1[ct] % P1, LL(a[l]) * pw2[ct] % P2};
else return {0, 0, 0};
}
int mid = (l + r) / 2;
if (mx[rs(i)] < Mx) return calc(ls(i), l, mid, Mx, ct);
else {
auto [x, y, z] = calc(rs(i), mid + 1, r, Mx, ct);
(y += LL(has1[i] + P1 - has1[rs(i)]) * ipw1[cnt[rs(i)]] % P1 * pw1[ct + x] % P1) %= P1;
(z += LL(has2[i] + P2 - has2[rs(i)]) * ipw2[cnt[rs(i)]] % P2 * pw2[ct + x] % P2) %= P2;
x += cnt[ls(i)];
return {x, y, z};
}
}
inline void upd(int i, int l, int r) {
int mid = (l + r) / 2;
mx[i] = max(mx[ls(i)], mx[rs(i)]);
tie(cnt[i], has1[i], has2[i]) = calc(ls(i), l, mid, mx[rs(i)], cnt[rs(i)]);
cnt[i] += cnt[rs(i)];
(has1[i] += has1[rs(i)]) %= P1;
(has2[i] += has2[rs(i)]) %= P2;
}
void build(int i, int l, int r) {
if (l == r) {
mx[i] = a[l], cnt[i] = 1, has1[i] = has2[i] = a[l];
return;
}
int mid = (l + r) / 2;
build(ls(i), l, mid);
build(rs(i), mid + 1, r);
upd(i, l, r);
}
void modify(int i, int l, int r, int x, int v) {
if (l == r) {
a[l] = v;
mx[i] = a[l], cnt[i] = 1, has1[i] = has2[i] = a[l];
return;
}
int mid = (l + r) / 2;
if (x <= mid) modify(ls(i), l, mid, x, v);
else modify(rs(i), mid + 1, r, x, v);
upd(i, l, r);
}
} A, B;
int main() {
cin.tie(0)->sync_with_stdio(0);
pw1[0] = ipw1[0] = 1, iB1 = qp(B1, P1 - 2, P1);
for (int i = 1; i <= N - 5; ++i) {
pw1[i] = LL(pw1[i - 1]) * B1 % P1;
ipw1[i] = LL(ipw1[i - 1]) * iB1 % P1;
}
pw2[0] = ipw2[0] = 1, iB2 = qp(B2, P2 - 2, P2);
for (int i = 1; i <= N - 5; ++i) {
pw2[i] = LL(pw2[i - 1]) * B2 % P2;
ipw2[i] = LL(ipw2[i - 1]) * iB2 % P2;
}
A.init(), B.init();
int q;
cin >> q;
while (q--) {
int o, x, y;
cin >> o >> x >> y;
if (o == 1) A.modify(1, 1, A.n, x, y);
else B.modify(1, 1, B.n, x, y);
cout << (A.has1[1] == B.has1[1] && A.has2[1] == B.has2[1] ? "YES\n" : "NO\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 17512kb
input:
5 1 2 3 4 5 5 5 4 3 2 1 8 1 1 5 1 4 2 1 2 4 1 5 1 1 5 5 2 1 4 2 3 5 2 5 5
output:
NO NO NO YES NO NO NO YES
result:
ok 8 tokens
Test #2:
score: 0
Accepted
time: 22ms
memory: 17124kb
input:
1 2 6 2 1 1 1 1 1 200000 2 6 2 1 1 1 1 1 1 1 1 2 2 1 1 1 1 2 1 1 1 2 4 1 2 1 2 1 1 1 1 1 2 2 5 1 1 1 1 1 1 2 1 1 1 2 6 1 1 1 2 1 1 2 1 1 2 2 3 1 1 1 1 2 1 1 2 6 2 1 1 2 2 4 1 1 1 2 2 6 1 1 1 2 1 1 1 2 5 2 2 6 2 1 1 1 2 4 2 2 5 2 2 6 2 1 1 1 2 5 1 2 6 2 1 1 2 1 1 1 1 1 1 2 4 1 1 1 2 1 1 2 1 1 2 2 3 2...
output:
NO NO NO NO YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES YES YES NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO YES YES 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 N...
result:
ok 200000 tokens
Test #3:
score: 0
Accepted
time: 26ms
memory: 16876kb
input:
6 2 1 1 2 1 2 1 1 200000 2 1 1 1 1 2 1 1 1 2 1 2 2 1 1 2 1 1 2 1 2 2 1 2 1 1 2 1 3 1 1 6 2 1 5 2 1 4 2 1 3 1 2 1 2 1 4 2 1 4 2 2 1 2 2 1 2 1 3 1 1 6 1 1 1 2 2 1 1 1 6 1 1 3 1 1 5 2 1 6 2 1 5 2 2 1 2 1 2 1 1 5 2 2 1 1 2 1 1 1 6 1 2 1 2 2 1 1 1 3 2 2 1 1 1 6 1 1 4 2 1 2 1 1 1 1 2 1 1 1 2 1 1 6 2 1 6 2...
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 NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO 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 200000 tokens
Test #4:
score: -100
Wrong Answer
time: 32ms
memory: 17448kb
input:
6 1 3 1 2 1 2 6 2 1 3 3 3 1 200000 2 4 2 1 2 1 1 6 2 2 3 2 1 1 1 1 6 2 1 6 2 1 3 2 2 6 1 2 4 3 1 1 2 2 5 2 2 6 2 2 3 1 1 4 3 1 3 1 2 5 2 2 4 2 2 1 3 1 1 1 2 2 2 2 4 2 1 5 3 1 6 3 2 6 3 1 5 3 2 5 3 2 4 1 2 4 2 1 1 2 1 6 1 2 6 1 1 2 3 1 1 3 1 1 1 2 6 3 2 4 1 1 4 2 2 2 1 1 3 1 1 1 3 1 1 3 1 4 3 1 3 3 2...
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 NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO 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 27th words differ - expected: 'YES', found: 'NO'