QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#589629 | #8338. Quad Kingdoms Chess | DBsoleil | RE | 0ms | 17576kb | C++20 | 3.7kb | 2024-09-25 19:11:51 | 2024-09-25 19:11:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
static constexpr int Maxn = 1e5 + 5, SqrN = 405, MaxB = 1205;
static constexpr uint64_t MOD1 = 1e9 + 9, MOD2 = 1e9 + 7;
static constexpr uint64_t BASE1 = 1e5 + 3, BASE2 = 1e5 + 19;
using hash_t = pair<uint64_t, uint64_t>;
hash_t operator + (hash_t lhs, int v)
{ return hash_t((lhs.first * BASE1 + v) % MOD1, (lhs.second * BASE2 + v) % MOD2); }
hash_t operator + (hash_t lhs, hash_t rhs)
{ return hash_t((lhs.first + rhs.first) % MOD1, (lhs.second + rhs.second) % MOD2); }
hash_t operator * (hash_t lhs, hash_t rhs)
{ return hash_t(lhs.first * rhs.first % MOD1, lhs.second * rhs.second % MOD2); }
const hash_t BASE = hash_t(BASE1, BASE2);
hash_t pw[Maxn];
using data_t = pair<int, hash_t>;
data_t operator + (data_t lhs, data_t rhs) {
if (lhs.first == 0) return rhs;
return data_t(lhs.first + rhs.first, hash_t(lhs.second * pw[rhs.first] + rhs.second));
} data_t New(uint64_t v) { return data_t(1, hash_t(v, v)); }
struct Array {
int n, bn, bs, a[Maxn];
int bel[Maxn], bL[Maxn], bR[Maxn];
data_t h[Maxn];
bool upd[Maxn];
vector<pair<int, data_t>> hv[MaxB];
void rebuild(int b) {
int l = bL[b], r = bR[b];
for (int i = l; i <= r; ++i) upd[i] = false;
h[l] = New(a[l]); upd[l] = true;
for (int i = l + 1, p = l; i <= r; ++i)
if (a[i] >= a[p])
h[i] = h[p] + New(a[i]), p = i, upd[i] = true;
else h[i] = h[i - 1];
hv[b].clear();
hash_t cur = {0, 0};
int len = 0;
for (int i = r; i >= l; --i)
if (upd[i]) {
(cur.first += pw[len].first * a[i]) %= MOD1;
(cur.second += pw[len].second * a[i]) %= MOD2;
++len;
hv[b].emplace_back(a[i], data_t(len, cur));
}
reverse(hv[b].begin(), hv[b].end());
} // Array::rebuild
data_t qblock(int b, data_t res, int &pre) {
int l = bL[b], r = bR[b];
auto it = lower_bound(hv[b].begin(), hv[b].end(), pair(pre, data_t()));
// fprintf(stderr, "l = %d, r = %d, it = %d\n", l, r, it - hv[b].begin());
// fprintf(stderr, "|hv[%d]| = %d\n", b, (int)hv[b].size()); fflush(stderr);
if (it == hv[b].end()) return res;
pre = hv[b].back().first;
// fprintf(stderr, "pre = %d\n", pre);
res = res + it->second;
return res;
} // qblock
data_t query(void) {
data_t res = h[bR[1]];
int cur = hv[1].back().first;
// fprintf(stderr, "cur = %d\n", cur);
for (int i = 2; i <= bn; ++i)
res = qblock(i, res, cur);
return res;
} // Array::query
void input(void) {
scanf("%d", &n); bs = (int)sqrt(n * log(n));
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
reverse(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i) bel[i] = (i - 1) / bs + 1;
bn = bel[n];
for (int i = 1; i <= bn; ++i) {
bL[i] = (i - 1) * bs + 1;
bR[i] = min(i * bs, n);
}
for (int i = 1; i <= bn; ++i) rebuild(i);
} // Array::input
void update(int x, int y) {
x = n - x + 1, a[x] = y;
rebuild(bel[x]);
} // update
} a[3];
int main(void) {
pw[0] = {1, 1};
for (int i = 1; i < Maxn; ++i)
pw[i] = pw[i - 1] * hash_t(BASE1, BASE2);
a[1].input(); a[2].input();
int qn; scanf("%d", &qn);
while (qn--) {
int op, x, y;
scanf("%d%d%d", &op, &x, &y);
a[op].update(x, y);
// fprintf(stderr, "------------------------- %d, %d, %d\n", op, x, y);
auto a1 = a[1].query(), a2 = a[2].query();
// fprintf(stderr, "a1 = (%d, (%lu, %lu))\n", a1.first, a1.second.first, a1.second.second);
// fprintf(stderr, "a2 = (%d, (%lu, %lu))\n", a2.first, a2.second.first, a2.second.second);
if (a1 != a2) printf("NO\n");
else printf("YES\n");
}
return 0;
} // main
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 17576kb
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: -100
Runtime Error
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...