QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#445888 | #8338. Quad Kingdoms Chess | ucup-team045 | WA | 25ms | 16900kb | C++20 | 2.4kb | 2024-06-16 16:38:58 | 2024-06-16 16:38:59 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<random>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const int maxn = 1e5 + 5;
ULL hsh[maxn];
struct SGT{
struct Info{
int mx; ULL hsh;
Info() : mx(0), hsh(0) {}
Info(int mx, ULL hsh) : mx(mx), hsh(hsh) {}
}tr[maxn * 4];
ULL query(int u, int l, int r, int mx){
if (tr[u].mx < mx) return 0;
if (l == r){
return tr[u].hsh;
}
int mid = (l + r) / 2;
if (tr[2 * u].mx < mx) return query(2 * u + 1, mid + 1, r, mx);
return query(2 * u, l, mid, mx) + tr[u].hsh - tr[2 * u].hsh;
}
void modify(int u, int l, int r, int x, int k){
if (l == r){
tr[u].mx = k;
tr[u].hsh = hsh[k];
return;
}
int mid = (l + r) / 2;
if (x <= mid) modify(2 * u, l, mid, x, k);
else modify(2 * u + 1, mid + 1, r, x, k);
tr[u].mx = max(tr[2 * u].mx, tr[2 * u + 1].mx);
tr[u].hsh = tr[2 * u].hsh + query(2 * u + 1, mid + 1, r, tr[2 * u].mx);
}
void build(int u, int l, int r, vector<int> &a){
if (l == r){
tr[u].mx = a[r];
tr[u].hsh = hsh[a[r]];
return;
}
int mid = (l + r) / 2;
build(2 * u, l, mid, a);
build(2 * u + 1, mid + 1, r, a);
tr[u].mx = max(tr[2 * u].mx, tr[2 * u + 1].mx);
tr[u].hsh = tr[2 * u].hsh + query(2 * u + 1, mid + 1, r, tr[2 * u].mx);
}
}tr1, tr2;
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
mt19937_64 rnd(4124235623523);
for(int i = 0; i < maxn; i++){
hsh[i] = rnd();
}
int n;
cin >> n;
vector<int> a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[n - i + 1];
tr1.build(1, 1, n, a);
int m;
cin >> m;
vector<int> b(m + 1);
for(int i = 1; i <= m; i++) cin >> b[m - i + 1];
tr2.build(1, 1, n, b);
int q;
cin >> q;
while(q--){
int op, x, y;
cin >> op >> x >> y;
if (op == 1){
tr1.modify(1, 1, n, n - x + 1, y);
}
else{
tr2.modify(1, 1, m, m - x + 1, y);
}
cout << (tr1.tr[1].hsh == tr2.tr[1].hsh ? "YES" : "NO") << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 16880kb
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
Wrong Answer
time: 25ms
memory: 16900kb
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:
YES NO NO YES 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...
result:
wrong answer 1st words differ - expected: 'NO', found: 'YES'