QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#534439 | #8338. Quad Kingdoms Chess | training_233 | WA | 32ms | 18200kb | C++17 | 2.2kb | 2024-08-27 10:13:19 | 2024-08-27 10:13:19 |
Judging History
answer
#include <cstdio>
#include <algorithm>
const int N = 1e5 + 10, mod = 1e9 + 7, base = 233;
typedef long long ll; int n[2], pw[N], a[2][N];
struct SegTree
{
#define ls(k) (k << 1)
#define rs(k) (k << 1 | 1)
int id;
struct Hash
{
int hsh, siz;
Hash(int x = 0, int y = 0) { hsh = x; siz = y; }
Hash operator+(const Hash& h) const
{
Hash ret;
ret.hsh = ((ll)pw[siz] * h.hsh + hsh) % mod;
ret.siz = h.siz + siz;
return ret;
}
Hash operator-(const Hash& h) const
{
Hash ret;
ret.hsh = (hsh + mod - (ll)pw[siz] * h.hsh % mod) % mod;
ret.siz = siz - h.siz;
return ret;
}
bool operator==(const Hash& h) const { return h.hsh == hsh && h.siz == siz; }
};
struct node{ Hash s; int mx, l, r; }h[N << 2];
Hash calc(int k, int pre)
{
if (h[k].l == h[k].r) return Hash(h[k].mx >= pre ? h[k].mx : 0, h[k].mx >= pre);
else
{
if (h[ls(k)].mx >= pre) return calc(ls(k), pre) + (h[k].s - h[ls(k)].s);
else return calc(rs(k), pre);
}
}
void pushup(int k)
{
h[k].s = h[ls(k)].s + calc(rs(k), h[ls(k)].mx);
h[k].mx = std::max(h[ls(k)].mx, h[rs(k)].mx);
}
void build(int k, int l, int r)
{
h[k].l = l; h[k].r = r;
if (l == r) return h[k].mx = a[id][l], h[k].s = Hash(a[id][l], 1), void();
int mid = (l + r) >> 1; build(ls(k), l, mid); build(rs(k), mid + 1, r);
pushup(k);
}
void change(int k, int p)
{
if (h[k].l == h[k].r) return h[k].mx = a[id][p], h[k].s = Hash(a[id][p], 1), void();
int mid = (h[k].l + h[k].r) >> 1;
if (p <= mid) change(ls(k), p);
else change(rs(k), p);
pushup(k);
}
#undef ls
#undef rs
}sgt[2];
int main()
{
pw[0] = 1; sgt[0].id = 0; sgt[1].id = 1;
for (int i = 1; i < N; ++i) pw[i] = (ll)pw[i - 1] * base % mod;
for (int p = 0; p < 2; ++p)
{
scanf("%d", &n[p]);
for (int i = 1; i <= n[p]; ++i) scanf("%d", &a[p][i]);
std::reverse(a[p] + 1, a[p] + n[p] + 1);
sgt[p].build(1, 1, n[p]);
}
int q; scanf("%d", &q);
for (int _ = 1, op, x, y; _ <= q; ++_)
{
scanf("%d%d%d", &op, &x, &y); --op;
x = n[op] + 1 - x; a[op][x] = y; sgt[op].change(1, x);
puts(sgt[0].h[1].s == sgt[1].h[1].s ? "YES" : "NO");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 17540kb
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: 32ms
memory: 17512kb
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: 32ms
memory: 18200kb
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: 27ms
memory: 17472kb
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 YES YES YES YES 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 N...
result:
wrong answer 123rd words differ - expected: 'YES', found: 'NO'