QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#349854 | #8338. Quad Kingdoms Chess | ucup-team2894# | WA | 31ms | 5972kb | C++20 | 4.1kb | 2024-03-10 06:45:39 | 2024-03-10 06:45:40 |
Judging History
answer
#include <bits/stdc++.h>
#define fr first
#define sc second
#define all(a) (a).begin(), (a).end()
#define unique(a) a.resize(unique(a.begin(), a.end()) - a.begin())
using namespace std;
#ifdef ONPC
mt19937 rnd(223);
#else
mt19937 rnd(chrono::high_resolution_clock::now()
.time_since_epoch().count());
#endif
#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)
using ll = long long;
using ld = double;
const int maxn = 1e5 + 100, inf = 1e9 + 100;
const int X = 100103, mod = 1e9 + 993;
int pw[maxn];
struct Hash {
int w = 0, len = 0;
void add(int x) {
// right
w = (w + x * (ll)pw[len]) % mod;
len++;
}
};
Hash combine(Hash const &x, Hash const &y) {
Hash w;
w.w = (x.w + y.w * (ll)pw[x.len]) % mod;
w.len = x.len + y.len;
return w;
}
struct Wo {
int n;
int a[maxn];
bool bad[maxn];
vector<int> vals;
vector<Hash> h;
vector<int> pos;
vector<int> ids;
void init(vector<int> pos_) {
pos = pos_;
reverse(all(pos));
for (int i = 0; i <= n; i++)
bad[i] = 0;
pos.push_back(0);
for (int i : pos)
bad[i] = 1;
int val = 0;
h.clear();
vals.clear();
ids.clear();
for (int i = n; i >= 0; i--) {
if (bad[i]) {
ids.push_back(vals.size());
vals.push_back(0);
} else {
if (a[i] >= val) {
val = a[i];
vals.push_back(a[i]);
}
}
}
h.resize(vals.size());
int last = -1;
for (int it = 0; it < pos.size(); it++) {
h[ids[it]] = {};
for (int i = ids[it] - 1; i > last; i--) {
h[i] = h[i + 1];
h[i].add(vals[i]);
}
last = ids[it];
}
}
Hash get() {
int val = 0;
Hash res = h[0];
for (int i = 0; i < ids.size() - 1; i++) {
int w = a[pos[i]];
if (w >= val) {
val = max(val, w);
int l = ids[i], r = ids[i + 1];
while (r - l > 1) {
int m = (l + r) / 2;
if (vals[m] >= val)
r = m;
else
l = m;
}
Hash tmp{};
tmp.add(w);
res = combine(combine(h[r], tmp), res);
}
val = max(val, vals[ids[i + 1] - 1]);
}
return res;
}
} q[2];
const int SQ = 100;
void solve() {
pw[0] = 1;
for (int i = 1; i < maxn; i++)
pw[i] = (pw[i - 1] * (ll)X) % mod;
for (int t = 0; t < 2; t++) {
int n;
cin >> n;
q[t].n = n;
for (int i = 1; i <= n; i++) {
cin >> q[t].a[i];
}
}
int zaps;
cin >> zaps;
vector<pair<int, pair<int, int>>> g(zaps);
for (int i = 0; i < zaps; i++) {
cin >> g[i].fr >> g[i].sc.fr >> g[i].sc.sc;
g[i].fr--;
}
for (int st = 0; st < zaps; st += SQ) {
vector<int> e[2];
int l = st;
int r = min(zaps, st + SQ);
for (int i = l; i < r; i++) {
e[g[i].fr].push_back(g[i].sc.fr);
}
for (int t = 0; t < 2; t++) {
sort(all(e[t]));
unique(e[t]);
q[t].init(e[t]);
}
for (int i = l; i < r; i++) {
q[g[i].fr].a[g[i].sc.fr] = g[i].sc.sc;
auto X = q[0].get();
auto Y = q[1].get();
// cerr << X.len << ' ' << Y.len << '\n';
if (X.w == Y.w && X.len == Y.len) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
}
}
int main() {
#ifdef ONPC
freopen("../a.in", "r", stdin);
// freopen("../a.out", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed;
cout.precision(20);
solve();
cerr << "\n\nConsumed " << TIME << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4252kb
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: 31ms
memory: 5972kb
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: -100
Wrong Answer
time: 27ms
memory: 5952kb
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:
wrong answer 90859th words differ - expected: 'NO', found: 'YES'