QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#534443 | #8338. Quad Kingdoms Chess | training_233 | WA | 32ms | 21840kb | C++17 | 2.5kb | 2024-08-27 10:17:43 | 2024-08-27 10:17:43 |
Judging History
answer
#include <cstdio>
#include <algorithm>
const int N = 1e5 + 10, mod1 = 1e9 + 7, mod2 = 1e9 + 9, base = 233;
typedef long long ll; int n[2], pw1[N], pw2[N], a[2][N];
struct SegTree
{
#define ls(k) (k << 1)
#define rs(k) (k << 1 | 1)
int id;
struct Hash
{
int hsh1, hsh2, siz;
Hash(int x = 0, int y = 0, int z = 0) { hsh1 = x; hsh2 = y; siz = z; }
Hash operator+(const Hash& h) const
{
Hash ret;
ret.hsh1 = ((ll)pw1[siz] * h.hsh1 + hsh1) % mod1;
ret.hsh2 = ((ll)pw2[siz] * h.hsh2 + hsh2) % mod2;
ret.siz = h.siz + siz;
return ret;
}
Hash operator-(const Hash& h) const
{
Hash ret;
ret.hsh1 = (hsh1 + mod1 - (ll)pw1[siz] * h.hsh1 % mod1) % mod1;
ret.hsh2 = (hsh2 + mod2 - (ll)pw2[siz] * h.hsh2 % mod2) % mod2;
ret.siz = siz - h.siz;
return ret;
}
bool operator==(const Hash& h) const { return h.hsh1 == hsh1 && h.hsh2 == hsh2 && 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 ? 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], 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], 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()
{
pw1[0] = pw2[0] = 1; sgt[0].id = 0; sgt[1].id = 1;
for (int i = 1; i < N; ++i) pw1[i] = (ll)pw1[i - 1] * base % mod1;
for (int i = 1; i < N; ++i) pw2[i] = (ll)pw2[i - 1] * base % mod2;
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 21028kb
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: 26ms
memory: 21736kb
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: 29ms
memory: 21716kb
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: 21840kb
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'