QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#348013 | #8338. Quad Kingdoms Chess | ucup-team2112# | WA | 80ms | 40480kb | C++20 | 3.6kb | 2024-03-09 16:37:01 | 2024-03-09 16:37:03 |
Judging History
answer
#include <bits/stdc++.h>
using pii = std::pair<int, int>;
const int base1 = 13331;
const int base2 = 233;
const int mod1 = 1e9 + 7;
const int mod2 = 1e9 + 9;
pii operator + (const pii &a, const pii &b){
return { (a.first + b.first) % mod1, (a.second + b.second) % mod2 };
}
pii operator - (const pii &a, const pii &b){
return { (a.first - b.first + mod1) % mod1, (a.second - b.second + mod2) % mod2 };
}
pii operator * (const pii &a, const pii &b){
return { (1LL * a.first * b.first) % mod1, (1LL * a.second * b.second) % mod2 };
}
pii get(const std::vector<pii> &h, int l, int r){
return h[r] - h[l - 1];
}
const int maxn = 4e5 + 233;
pii pw[maxn];
struct Segment_Tree{
pii h[maxn << 2];
int mx[maxn << 2];
int len[maxn << 2];
#define ls o << 1
#define rs o << 1 | 1
std::pair<int, pii> merge(int o, int l, int r, int v) {
if (mx[o] < v) return make_pair(0, pii(0, 0));
if (l == r) {
return {len[o], h[o]};
}
int mid = (l + r) >> 1;
if (mx[rs] < v) {
auto cc = merge(ls, l, mid, v);
return cc;
}
auto [a, b] = merge(rs, mid + 1, r, v);
// std::cerr << "!!: " << l << " " << r << " " << mid << " " << len[ls] << "\n";
return {len[o] - len[rs] + a, (h[o] - h[rs]) * pw[a] + b};
}
void up(int o, int l, int r) {
mx[o] = std::max(mx[ls], mx[rs]);
int mid = (l + r) >> 1;
auto [a, b] = merge(ls, l, mid, mx[rs]);
h[o] = h[rs] + b * pw[len[rs]];
len[o] = len[rs] + a;
// std::cerr << o << " " << l << " " << r << " " << a << "\n";
}
void modify(int o, int tl, int tr, int l, int r, int v) {
if (l > tr || r < tl) return;
if (l <= tl && tr <= r) {
h[o] = pii(v, v);
mx[o] = v;
len[o] = 1;
return;
}
int mid = (tl + tr) >> 1;
modify(ls, tl, mid, l, r, v);
modify(rs, mid + 1, tr, l, r, v);
up(o, tl, tr);
}
// pii query(int o, int tl, int tr, int l, int r) {
// if (l > tr || r < tl) return pii(0, 0);
// if (l <= tl && tr <= r) {
// return h[o];
// }
// int mid = (tl + tr) >> 1;
// auto res = merge(ls, tl, mid, mx[rs]) + query(rs, mid + 1, tr, l, r);
// return res;
// }
}A, B;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
pw[0] = pii(1, 1);
for (int i = 1; i < maxn; i++) {
pw[i] = pw[i - 1] * pii(base1, base2);
}
int n, m;
std::cin >> n;
for (int i = 1; i <= n; i += 1) {
int x;
std::cin >> x;
// std::cerr << "!: " << i << "\n";
A.modify(1, 1, n, i, i, x);
}
std::cin >> m;
for (int i = 1; i <= m; i += 1) {
int x;
std::cin >> x;
// std::cerr << "!: " << i << "\n";
B.modify(1, 1, m, i, i, x);
}
// std::cout << (A.h[1] == B.h[1] ? "YES" : "NO") << std::endl;
// auto cc1 = A.h[1];
// auto cc2 = B.h[1];
// std::cout << cc1.first << " " << cc1.second << " " << A.len[1] << std::endl;
// std::cout << cc2.first << " " << cc2.second << " " << B.len[1] << std::endl;
int q;
std::cin >> q;
while (q--) {
int o, x, y;
std::cin >> o >> x >> y;
if (o == 1) {
A.modify(1, 1, n, x, x, y);
}
else {
B.modify(1, 1, m, x, x, y);
}
std::cout << (A.h[1] == B.h[1] ? "YES" : "NO") << std::endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 40472kb
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: 51ms
memory: 40428kb
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: 80ms
memory: 38360kb
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: 76ms
memory: 40480kb
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'