QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#726331 | #8338. Quad Kingdoms Chess | ucup-team3646 | WA | 131ms | 3664kb | C++20 | 2.0kb | 2024-11-08 23:03:13 | 2024-11-08 23:03:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define rep2(i, l, r) for (ll i = ll(l); i < ll(r); i++)
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
constexpr ll mod = (1LL << 61) - 1;
vll H;
struct tree {
struct node {
ll hash = 0, hashL = 0;
int max = 0;
};
int N, sz;
vector<node> data;
tree(int n) : N(n) {
sz = 1;
while (sz < N) sz <<= 1;
data.assign(2 * sz, {0, 0, 0});
}
void set(int pos, int val) {
pos += sz;
data[pos].max = val;
data[pos].hash = H[val];
data[pos].hashL = H[val];
while (pos >>= 1) upd(pos);
}
ll get(int k, int x) {
if (k >= sz) {
int val = data[k].max;
if (val >= x)
return H[val];
else
return 0;
}
if (x > data[2 * k + 1].max) return get(2 * k, x);
return (data[k].hashL + get(2 * k + 1, x)) % mod;
}
void upd(int k) {
data[k].max = max(data[2 * k].max, data[2 * k + 1].max);
data[k].hashL = get(2 * k, data[2 * k + 1].max);
data[k].hash = (data[k].hashL + data[2 * k + 1].hash) % mod;
}
};
ll seed = 1;
ll rnd() {
seed += 0x9e3779b97f4a7c15;
seed = (seed ^ (seed >> 30)) * 0xbf58476d1ce4e5b9;
seed = (seed ^ (seed >> 27)) * 0x94d049bb133111eb;
return seed ^ (seed >> 31);
}
int main() {
int m = 1e5 + 10;
H.resize(m);
rep(i, m) { H[i] = rnd() % mod; }
int n1, n2;
cin >> n1;
vi a1(n1);
rep(i, n1) cin >> a1[i];
cin >> n2;
vi a2(n2);
rep(i, n2) cin >> a2[i];
tree T1(n1), T2(n2);
rep(i, n1) T1.set(i, a1[i]);
rep(i, n2) T2.set(i, a2[i]);
int q;
cin >> q;
while (q--) {
int t, x, y;
cin >> t >> x >> y;
x--;
if (t == 1)
T1.set(x, y);
else
T2.set(x, y);
ll hash1 = T1.get(1, 0), hash2 = T2.get(1, 0);
if (hash1 == hash2)
cout << "YES\n";
else
cout << "NO\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3652kb
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: 131ms
memory: 3664kb
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 NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO 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 5th words differ - expected: 'YES', found: 'NO'