QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#358718 | #8338. Quad Kingdoms Chess | Kirill22# | WA | 27ms | 4424kb | C++23 | 3.0kb | 2024-03-19 23:05:21 | 2024-03-19 23:05:23 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
const int N = (int) 2e5;
const int mod = (int) 1e9 + 7, p = 1010101;
int pw[N];
struct tree {
struct node {
int mx, res, cnt;
};
vector<node> t;
void update(int v, int l, int r, int& res, int& cnt, int& mx) {
if (t[v].mx < mx) {
return;
}
if (l + 1 == r) {
res = (res + pw[cnt] * 1ll * t[v].mx) % mod;
cnt++;
mx = max(mx, t[v].mx);
return;
}
if (t[v * 2 + 2].mx < mx) {
update(v * 2 + 1, l, (l + r) / 2, res, cnt, mx);
} else {
update(v * 2 + 2, (l + r) / 2, r, res, cnt, mx);
res = (res + pw[cnt] * 1ll * t[v * 2 + 1].res) % mod;
cnt += t[v * 2 + 1].cnt;
mx = max(mx, t[v].mx);
}
}
void upd(int v, int l, int r) {
int res = t[v * 2 + 2].res;
int cnt = t[v * 2 + 2].cnt;
int mx = t[v * 2 + 2].mx;
update(v * 2 + 1, l, (l + r) / 2, res, cnt, mx);
t[v].mx = max(t[v * 2 + 1].mx, t[v * 2 + 2].mx);
t[v].res = res;
t[v].cnt = cnt;
}
void build(int v, int l, int r, const vector<int>& a) {
if (l + 1 == r) {
t[v].mx = t[v].res = a[l];
t[v].cnt = 1;
return;
}
int m = (l + r) / 2;
build(v * 2 + 1, l, m, a);
build(v * 2 + 2, m, r, a);
upd(v, l, r);
}
tree(int n, const vector<int>& a) {
t.resize(4 * n);
build(0, 0, n, a);
}
void set(int v, int l, int r, int i, int x) {
if (l + 1 == r) {
t[v].mx = t[v].res = x;
t[v].cnt = 1;
return;
}
int m = (l + r) / 2;
if (i < m) {
set(v * 2 + 1, l, m, i, x);
} else {
set(v * 2 + 2, m, r, i, x);
}
upd(v, l, r);
}
};
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
tree A(n, a);
int m;
cin >> m;
vector<int> b(m);
for (int i = 0; i < m; i++) {
cin >> b[i];
}
tree B(m, b);
int q;
cin >> q;
// cout << A.t[0] << " " << B.t[0] << endl;
while (q--) {
int k, i, x;
cin >> k >> i >> x;
k--, i--;
if (k == 0) {
A.set(0, 0, n, i, x);
} else {
B.set(0, 0, m, i, x);
}
// cout << A.t[0] << " " << B.t[0] << endl;
// cout << A.c[0] << " " << B.c[0] << endl;
if (A.t[0].res == B.t[0].res) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
pw[0] = 1;
for (int i = 1; i < N; i++) {
pw[i] = pw[i - 1] * 1ll * p % mod;
}
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 4424kb
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: 4348kb
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: 27ms
memory: 4396kb
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: 4408kb
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'