# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
973447 |
2024-05-02T02:37:26 Z |
cot7302 |
Joker (BOI20_joker) |
C++17 |
|
1 ms |
2396 KB |
#include <bits/stdc++.h>
using namespace std;
struct disjoint_set {
int n, odd_cir;
vector<int> _, odd_cir_op;
vector<tuple<int, int, int>> op;
disjoint_set(int n) : n(n), odd_cir(0), _(2 * n + 1, -1), odd_cir_op(), op() {}
int root(int x) { while (_[x] > 0) x = _[x]; return x; }
void __join(int a, int b) {
a = root(a), b = root(b);
if (a == b) return;
if (_[a] > _[b]) swap(a, b);
op.emplace_back(a, b, _[b]);
_[a] += _[b];
_[b] = a;
}
void join(int a, int b) {
__join(a, b + n);
__join(a + n, b);
odd_cir += odd_cir_op.emplace_back(root(a) == root(b));
}
void join(pair<int, int> x) {
auto [a, b] = x;
join(a, b);
}
bool is_bipartite() const {
return odd_cir;
}
void roll_back(int cnta, int cntb) {
while (cnta != (int)size(op)) {
auto [a, b, sz] = op.back();
_[a] -= sz;
_[b] = sz;
op.pop_back();
}
while (cntb != (int)size(odd_cir_op)) {
odd_cir -= odd_cir_op.back();
odd_cir_op.pop_back();
}
}
void roll_back(pair<int, int> x) {
roll_back(x.first, x.second);
}
pair<int, int> snapshot() const {
return {(int)size(op), (int)size(odd_cir_op)};
}
};
pair<int, int> edges[200001];
int ans[200001];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m, q; cin >> n >> m >> q;
for (int i = 1; i <= m; i++) cin >> edges[i].first >> edges[i].second;
disjoint_set dsu(n);
for (int i = 1; i <= m; i++) dsu.join(edges[i]);
if (dsu.is_bipartite()) {
while (q--) cout << "NO\n";
return 0;
}
dsu.roll_back(0, 0);
auto solve = [&](auto&& f, int l, int r, int ql, int qr) -> void {
if (l > r) return;
int mid = (l + r) >> 1;
auto snap = dsu.snapshot();
for (int i = l; i < mid; i++) dsu.join(edges[i]);
int opt = qr;
while (dsu.is_bipartite()) dsu.join(edges[opt--]);
ans[mid] = opt;
dsu.roll_back(snap);
snap = dsu.snapshot();
for (int i = opt + 1; i <= qr; i++) dsu.join(edges[i]);
f(f, l, mid - 1, ql, opt);
dsu.roll_back(snap);
snap = dsu.snapshot();
for (int i = l; i <= mid; i++) dsu.join(edges[i]);
f(f, mid + 1, r, opt, qr);
dsu.roll_back(snap);
};
solve(solve, 1, m, 0, m);
//for (int i = 0; i < m; i++) cout << ans[i] << " \n"[i == m - 1];
for (int l, r; q--; ) {
cin >> l >> r;
cout << ((r <= ans[l]) ? "YES\n" : "NO\n");
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |