QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#348709 | #8338. Quad Kingdoms Chess | ucup-team1600# | WA | 22ms | 22752kb | C++20 | 5.6kb | 2024-03-09 20:38:23 | 2024-03-09 20:38:24 |
Judging History
answer
#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
template<typename T>
bool umin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool umax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#ifdef KIVI
#define DEBUG for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template<class ...Ts>
auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define DEBUG while (false)
#define LOG(...)
#endif
mt19937 rng(4242);
const int max_n = 1e5 + 42, inf = 1000111222;
template<typename TKey, typename TSum>
class min_records_segment_tree {
private:
struct node {
TKey min;
TSum ans, ans_right_after_left;
node() {
min = 0;
ans = 0;
ans_right_after_left = numeric_limits<TSum>::min();
}
template<typename TValue>
node(TKey key, TValue value) {
min = key;
ans = value;
ans_right_after_left = numeric_limits<TSum>::min();
}
};
node t[4 * max_n];
node merge(const node& l, int r) {
node res;
res.min = min(l.min, t[r].min);
res.ans_right_after_left = 0;
while(true) {
if(t[r].min >= l.min) {
break;
} else if(t[r].ans_right_after_left == numeric_limits<TSum>::min()) {
res.ans_right_after_left += t[r].ans;
break;
} else if(t[r * 2].min >= l.min) {
r = r * 2 + 1;
} else {
res.ans_right_after_left += t[r].ans_right_after_left;
r = r * 2;
}
}
res.ans = l.ans + res.ans_right_after_left;
return res;
}
void get_min_records_internal(int v, int tl, int tr, int l, int r, node& res) {
if(tl == l && tr == r) {
res = merge(res, v);
return;
}
int mid = (tl + tr) / 2;
if(r <= mid) {
get_min_records_internal(2 * v, tl, mid, l, r, res);
return;
} else if(l > mid) {
get_min_records_internal(2 * v + 1, mid + 1, tr, l, r, res);
return;
}
get_min_records_internal(2 * v, tl, mid, l, mid, res);
get_min_records_internal(2 * v + 1, mid + 1, tr, mid + 1, r, res);
}
public:
template<typename TValue>
void build(int v, int l, int r, const pair<TKey, TValue> a[]) {
if(l == r) {
t[v] = node(a[l].fi, a[l].se);
return;
}
int mid = (l + r) / 2;
build((v << 1), l, mid, a);
build((v << 1) + 1, mid + 1, r, a);
t[v] = merge(t[(v << 1)], (v << 1) + 1);
}
template<typename TValue>
void update(int v, int l, int r, int pos, pair<TKey, TValue> elem) {
if(l == r) {
t[v] = node(elem.fi, elem.se);
return;
}
int mid = (l + r) / 2;
if(pos <= mid) {
update(2 * v, l, mid, pos, elem);
} else {
update(2 * v + 1, mid + 1, r, pos, elem);
}
t[v] = merge(t[2 * v], 2 * v + 1);
}
TSum get_min_records(int v, int tl, int tr, int l, int r, TKey start_value = numeric_limits<TKey>::max()) {
node res(start_value, 0);
get_min_records_internal(v, tl, tr, l, r, res);
return res.ans;
}
};
int h[max_n];
min_records_segment_tree<int, ll> t1, t2;
void solve() {
int n, m, q;
cin >> n;
vector <int> a(n);
for (auto &i : a) cin >> i;
cin >> m;
vector <int> b(m);
for (auto &i : b) cin >> i;
reverse(all(a));
reverse(all(b));
cin >> q;
vector <pair<int, ll> > A(n), B(m);
for (int i = 0; i < n; i++) {
A[i].first = -a[i];
A[i].second = h[a[i]];
}
for (int i = 0; i < m; i++) {
B[i].first = -b[i];
B[i].second = h[b[i]];
}
t1.build(1, 0, n - 1, A.data());
t2.build(1, 0, m - 1, B.data());
while (q--) {
int t, l, r;
cin >> t >> l >> r;
--l;
if (t == 1) {
l = n - 1 - l;
A[l].first = -r;
A[l].second = h[r];
t1.update(1, 0, n - 1, l, A[l]);
}
else {
l = m - 1 - l;
B[l].first = -r;
B[l].second = h[r];
t2.update(1, 0, n - 1, l, B[l]);
}
ll val1 = t1.get_min_records(1, 0, n - 1, 0, n - 1);
ll val2 = t2.get_min_records(1, 0, m - 1, 0, m - 1);
if (val1 == val2) {
cout << "YES\n";
}
else {
cout << "NO\n";
}
}
}
template<typename T = int>
inline T randll(T l = INT_MIN, T r = INT_MAX) {
return uniform_int_distribution<T>(l, r)(rng);
}
inline ld randld(ld l = INT_MIN, ld r = INT_MAX) {
return uniform_real_distribution<ld>(l, r)(rng);
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < max_n; i++) {
h[i] = randll(1, (1 << 30) - 1);
}
int t = 1;
// cin >> t;
while (t--) solve();
}
/*
KIVI
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 22672kb
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: 22ms
memory: 22752kb
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 NO NO YES YES NO NO YES NO YES NO YES YES NO NO NO NO YES YES NO YES NO NO NO NO YES NO NO NO NO NO NO NO YES NO YES NO NO YES NO NO NO YES NO YES YES YES YES NO YES YES YES NO YES NO NO YES YES NO NO NO YES YES YES YES NO NO NO NO YES NO YES YES NO YES YES NO NO NO NO NO YES NO NO YES...
result:
wrong answer 1st words differ - expected: 'NO', found: 'YES'