# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
993852 |
2024-06-06T14:21:04 Z |
Fatonim |
Joker (BOI20_joker) |
C++17 |
|
2000 ms |
31716 KB |
// "We create our own demons."
#include <bits/stdc++.h>
using namespace std;
#ifdef ONPC
#include "debug.h"
#else
#define dbg(...)
#endif
#define int long long
#define ll long long
#define ld long double
#define pi pair<int, int>
// vector
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define maxel(x) (*max_element(all(x)))
#define minel(x) (*min_element(all(x)))
#define maxpos(x) (max_element(all(x)) - x.begin())
#define minpos(x) (min_element(all(x)) - x.begin())
#define srt(x) (sort(all(x)))
#define rev(x) (reverse(all(x)))
// bitwise operations
#define cnt_bit(n) __builtin_popcountll(n)
#define low_bit(n) ((n) & (-(n)))
#define bit(n, i) (((n) >> (i)) & 1)
#define set_bit(n, i) ((n) | (1LL << (i)))
#define reset_bit(n, i) ((n) & ~(1LL << (i)))
#define flip_bit(n, i) ((n) ^ (1LL << (i)))
// math
#define sqr(n) ((n) * (n))
#define divup(a, b) (((a) + (b)-1) / (b))
// ostream
#define Fixed(a) cout << fixed << setprecision(12) << a;
template <class T> void chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template <class T> void chmax(T& a, const T& b) { return b > a ? a = b, 1 : 0; }
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> using max_queue = priority_queue<T, vector<T>, less<T>>;
template <class T> using V = vector<T>;
using vi = V<int>;
using vd = V<ld>;
using vb = V<bool>;
using vpi = V<pi>;
using vvi = V<vi>;
using vvb = V<vb>;
const int mod = 1e9 + 7; // 998244353 1e9 + 7
const ll inf = (int)(1e18) + 7;
const int inf_s = 1e9 + 7;
const ld eps = 1e-9;
const int B = 32;
const int N = 1000 + 3;
const int logn = 20;
const int maxn = 4e5 + 7;
/////////////////////////solve/////////////////////////
const int bs = 4500;
const int bc = maxn / bs + 1;
struct query {
int l, r, i;
};
V<query> b[maxn];
pi e[maxn];
int ans[maxn];
int p[maxn], sz[maxn], len[maxn];
vi hist;
pi get(int a) {
if (a != p[a]) {
pi cur = get(p[a]);
return {cur.first, cur.second ^ len[a]};
}
return {a, 0};
}
bool unite(int aa, int bb) {
auto [a, x] = get(aa);
auto [b, y] = get(bb);
if (a == b) {
dbg(a, b, aa, bb);
dbg(p[aa], p[bb]);
return x ^ y ^ 1;
}
if (sz[a] > sz[b]) swap(a, b);
sz[b] += sz[a];
p[a] = b;
len[a] = x ^ y ^ 1;
hist.push_back(a);
return 0;
}
void rb(int k) {
while (sz(hist) > k) {
int a = hist.back();
hist.pop_back();
sz[p[a]] -= sz[a];
p[a] = a;
len[a] = 0;
}
}
void solve() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 0; i < n; ++i) {
sz[i] = 1;
p[i] = i;
len[i] = 0;
}
for (int i = 0; i < m; ++i) {
int v, u;
cin >> v >> u;
--v; --u;
e[i] = {v, u};
e[i + m] = {v, u};
}
for (int qi = 0; qi < q; ++qi) {
int l, r;
cin >> l >> r;
--l, --r;
int nl = r + 1, nr = m + l - 1;
b[nl / bs].push_back({nl, nr, qi});
}
for (int bi = 0; bi < bc; ++bi) {
sort(all(b[bi]), [](query& a, query& b) {return a.r < b.r;});
int st = (bi + 1) * bs;
int cur_r = st;
int res = 0;
for (auto& [l, r, qi] : b[bi]) {
dbg(bi, qi, l, r, res);
while (cur_r <= r) {
res |= unite(e[cur_r].first, e[cur_r].second);
++cur_r;
dbg(e[cur_r], cur_r);
}
int k = sz(hist), add = 0;
for (int i = l; i <= min(r, st - 1); ++i) {
add |= unite(e[i].first, e[i].second);
dbg(e[i], i);
}
dbg(res, add);
rb(k);
ans[qi] = res | add;
}
rb(0);
}
for (int qi = 0; qi < q; ++qi) {
cout << (ans[qi] ? "YES" : "NO") << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef ONPC
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
int t = 1;
//cin >> t;
for (int i = 1; i <= t; ++i) {
#ifdef ONPC
cerr << "===========" << i << "===========" << '\n';
#endif
solve();
}
#ifdef ONPC
cerr << endl << "Time " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
9820 KB |
Output is correct |
2 |
Correct |
3 ms |
9820 KB |
Output is correct |
3 |
Correct |
3 ms |
9816 KB |
Output is correct |
4 |
Correct |
3 ms |
9820 KB |
Output is correct |
5 |
Correct |
4 ms |
9820 KB |
Output is correct |
6 |
Correct |
3 ms |
9820 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9836 KB |
Output is correct |
9 |
Correct |
3 ms |
9820 KB |
Output is correct |
10 |
Correct |
5 ms |
9852 KB |
Output is correct |
11 |
Correct |
4 ms |
9816 KB |
Output is correct |
12 |
Correct |
3 ms |
10052 KB |
Output is correct |
13 |
Correct |
4 ms |
9884 KB |
Output is correct |
14 |
Correct |
4 ms |
9816 KB |
Output is correct |
15 |
Correct |
4 ms |
9820 KB |
Output is correct |
16 |
Correct |
3 ms |
9820 KB |
Output is correct |
17 |
Correct |
3 ms |
9820 KB |
Output is correct |
18 |
Correct |
4 ms |
9820 KB |
Output is correct |
19 |
Correct |
4 ms |
9820 KB |
Output is correct |
20 |
Correct |
4 ms |
9820 KB |
Output is correct |
21 |
Correct |
4 ms |
9820 KB |
Output is correct |
22 |
Correct |
4 ms |
10000 KB |
Output is correct |
23 |
Correct |
3 ms |
10000 KB |
Output is correct |
24 |
Correct |
5 ms |
9820 KB |
Output is correct |
25 |
Correct |
4 ms |
10020 KB |
Output is correct |
26 |
Correct |
3 ms |
9816 KB |
Output is correct |
27 |
Correct |
5 ms |
9820 KB |
Output is correct |
28 |
Correct |
3 ms |
9820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
9820 KB |
Output is correct |
2 |
Correct |
3 ms |
9820 KB |
Output is correct |
3 |
Correct |
3 ms |
9816 KB |
Output is correct |
4 |
Correct |
3 ms |
9820 KB |
Output is correct |
5 |
Correct |
4 ms |
9820 KB |
Output is correct |
6 |
Correct |
3 ms |
9820 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9836 KB |
Output is correct |
9 |
Correct |
3 ms |
9820 KB |
Output is correct |
10 |
Correct |
5 ms |
9852 KB |
Output is correct |
11 |
Correct |
4 ms |
9816 KB |
Output is correct |
12 |
Correct |
3 ms |
10052 KB |
Output is correct |
13 |
Correct |
4 ms |
9884 KB |
Output is correct |
14 |
Correct |
4 ms |
9816 KB |
Output is correct |
15 |
Correct |
4 ms |
9820 KB |
Output is correct |
16 |
Correct |
3 ms |
9820 KB |
Output is correct |
17 |
Correct |
3 ms |
9820 KB |
Output is correct |
18 |
Correct |
4 ms |
9820 KB |
Output is correct |
19 |
Correct |
4 ms |
9820 KB |
Output is correct |
20 |
Correct |
4 ms |
9820 KB |
Output is correct |
21 |
Correct |
4 ms |
9820 KB |
Output is correct |
22 |
Correct |
4 ms |
10000 KB |
Output is correct |
23 |
Correct |
3 ms |
10000 KB |
Output is correct |
24 |
Correct |
5 ms |
9820 KB |
Output is correct |
25 |
Correct |
4 ms |
10020 KB |
Output is correct |
26 |
Correct |
3 ms |
9816 KB |
Output is correct |
27 |
Correct |
5 ms |
9820 KB |
Output is correct |
28 |
Correct |
3 ms |
9820 KB |
Output is correct |
29 |
Correct |
20 ms |
10076 KB |
Output is correct |
30 |
Correct |
24 ms |
10076 KB |
Output is correct |
31 |
Correct |
28 ms |
10072 KB |
Output is correct |
32 |
Correct |
27 ms |
10072 KB |
Output is correct |
33 |
Correct |
35 ms |
10072 KB |
Output is correct |
34 |
Correct |
27 ms |
10076 KB |
Output is correct |
35 |
Correct |
28 ms |
10076 KB |
Output is correct |
36 |
Correct |
19 ms |
10076 KB |
Output is correct |
37 |
Correct |
28 ms |
10168 KB |
Output is correct |
38 |
Correct |
30 ms |
10076 KB |
Output is correct |
39 |
Correct |
21 ms |
10076 KB |
Output is correct |
40 |
Correct |
22 ms |
10072 KB |
Output is correct |
41 |
Correct |
22 ms |
10076 KB |
Output is correct |
42 |
Correct |
21 ms |
10072 KB |
Output is correct |
43 |
Correct |
45 ms |
10076 KB |
Output is correct |
44 |
Correct |
42 ms |
10076 KB |
Output is correct |
45 |
Correct |
40 ms |
10268 KB |
Output is correct |
46 |
Correct |
38 ms |
10076 KB |
Output is correct |
47 |
Correct |
23 ms |
10076 KB |
Output is correct |
48 |
Correct |
25 ms |
10332 KB |
Output is correct |
49 |
Correct |
25 ms |
10076 KB |
Output is correct |
50 |
Correct |
27 ms |
10292 KB |
Output is correct |
51 |
Correct |
28 ms |
10260 KB |
Output is correct |
52 |
Correct |
31 ms |
10324 KB |
Output is correct |
53 |
Correct |
27 ms |
10076 KB |
Output is correct |
54 |
Correct |
28 ms |
10076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
9820 KB |
Output is correct |
2 |
Correct |
3 ms |
9820 KB |
Output is correct |
3 |
Execution timed out |
2019 ms |
31716 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
9820 KB |
Output is correct |
2 |
Correct |
3 ms |
9820 KB |
Output is correct |
3 |
Correct |
3 ms |
9816 KB |
Output is correct |
4 |
Correct |
3 ms |
9820 KB |
Output is correct |
5 |
Correct |
4 ms |
9820 KB |
Output is correct |
6 |
Correct |
3 ms |
9820 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9836 KB |
Output is correct |
9 |
Correct |
3 ms |
9820 KB |
Output is correct |
10 |
Correct |
5 ms |
9852 KB |
Output is correct |
11 |
Correct |
4 ms |
9816 KB |
Output is correct |
12 |
Correct |
3 ms |
10052 KB |
Output is correct |
13 |
Correct |
4 ms |
9884 KB |
Output is correct |
14 |
Correct |
4 ms |
9816 KB |
Output is correct |
15 |
Correct |
4 ms |
9820 KB |
Output is correct |
16 |
Correct |
3 ms |
9820 KB |
Output is correct |
17 |
Correct |
3 ms |
9820 KB |
Output is correct |
18 |
Correct |
4 ms |
9820 KB |
Output is correct |
19 |
Correct |
4 ms |
9820 KB |
Output is correct |
20 |
Correct |
4 ms |
9820 KB |
Output is correct |
21 |
Correct |
4 ms |
9820 KB |
Output is correct |
22 |
Correct |
4 ms |
10000 KB |
Output is correct |
23 |
Correct |
3 ms |
10000 KB |
Output is correct |
24 |
Correct |
5 ms |
9820 KB |
Output is correct |
25 |
Correct |
4 ms |
10020 KB |
Output is correct |
26 |
Correct |
3 ms |
9816 KB |
Output is correct |
27 |
Correct |
5 ms |
9820 KB |
Output is correct |
28 |
Correct |
3 ms |
9820 KB |
Output is correct |
29 |
Execution timed out |
2019 ms |
31716 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
9820 KB |
Output is correct |
2 |
Correct |
3 ms |
9820 KB |
Output is correct |
3 |
Correct |
3 ms |
9816 KB |
Output is correct |
4 |
Correct |
3 ms |
9820 KB |
Output is correct |
5 |
Correct |
4 ms |
9820 KB |
Output is correct |
6 |
Correct |
3 ms |
9820 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9836 KB |
Output is correct |
9 |
Correct |
3 ms |
9820 KB |
Output is correct |
10 |
Correct |
5 ms |
9852 KB |
Output is correct |
11 |
Correct |
4 ms |
9816 KB |
Output is correct |
12 |
Correct |
3 ms |
10052 KB |
Output is correct |
13 |
Correct |
4 ms |
9884 KB |
Output is correct |
14 |
Correct |
4 ms |
9816 KB |
Output is correct |
15 |
Correct |
4 ms |
9820 KB |
Output is correct |
16 |
Correct |
3 ms |
9820 KB |
Output is correct |
17 |
Correct |
3 ms |
9820 KB |
Output is correct |
18 |
Correct |
4 ms |
9820 KB |
Output is correct |
19 |
Correct |
4 ms |
9820 KB |
Output is correct |
20 |
Correct |
4 ms |
9820 KB |
Output is correct |
21 |
Correct |
4 ms |
9820 KB |
Output is correct |
22 |
Correct |
4 ms |
10000 KB |
Output is correct |
23 |
Correct |
3 ms |
10000 KB |
Output is correct |
24 |
Correct |
5 ms |
9820 KB |
Output is correct |
25 |
Correct |
4 ms |
10020 KB |
Output is correct |
26 |
Correct |
3 ms |
9816 KB |
Output is correct |
27 |
Correct |
5 ms |
9820 KB |
Output is correct |
28 |
Correct |
3 ms |
9820 KB |
Output is correct |
29 |
Correct |
20 ms |
10076 KB |
Output is correct |
30 |
Correct |
24 ms |
10076 KB |
Output is correct |
31 |
Correct |
28 ms |
10072 KB |
Output is correct |
32 |
Correct |
27 ms |
10072 KB |
Output is correct |
33 |
Correct |
35 ms |
10072 KB |
Output is correct |
34 |
Correct |
27 ms |
10076 KB |
Output is correct |
35 |
Correct |
28 ms |
10076 KB |
Output is correct |
36 |
Correct |
19 ms |
10076 KB |
Output is correct |
37 |
Correct |
28 ms |
10168 KB |
Output is correct |
38 |
Correct |
30 ms |
10076 KB |
Output is correct |
39 |
Correct |
21 ms |
10076 KB |
Output is correct |
40 |
Correct |
22 ms |
10072 KB |
Output is correct |
41 |
Correct |
22 ms |
10076 KB |
Output is correct |
42 |
Correct |
21 ms |
10072 KB |
Output is correct |
43 |
Correct |
45 ms |
10076 KB |
Output is correct |
44 |
Correct |
42 ms |
10076 KB |
Output is correct |
45 |
Correct |
40 ms |
10268 KB |
Output is correct |
46 |
Correct |
38 ms |
10076 KB |
Output is correct |
47 |
Correct |
23 ms |
10076 KB |
Output is correct |
48 |
Correct |
25 ms |
10332 KB |
Output is correct |
49 |
Correct |
25 ms |
10076 KB |
Output is correct |
50 |
Correct |
27 ms |
10292 KB |
Output is correct |
51 |
Correct |
28 ms |
10260 KB |
Output is correct |
52 |
Correct |
31 ms |
10324 KB |
Output is correct |
53 |
Correct |
27 ms |
10076 KB |
Output is correct |
54 |
Correct |
28 ms |
10076 KB |
Output is correct |
55 |
Correct |
182 ms |
21960 KB |
Output is correct |
56 |
Correct |
270 ms |
25544 KB |
Output is correct |
57 |
Correct |
258 ms |
24984 KB |
Output is correct |
58 |
Correct |
254 ms |
22016 KB |
Output is correct |
59 |
Correct |
416 ms |
21856 KB |
Output is correct |
60 |
Correct |
447 ms |
24520 KB |
Output is correct |
61 |
Correct |
301 ms |
21972 KB |
Output is correct |
62 |
Correct |
362 ms |
25036 KB |
Output is correct |
63 |
Correct |
391 ms |
19924 KB |
Output is correct |
64 |
Correct |
417 ms |
22472 KB |
Output is correct |
65 |
Correct |
471 ms |
25028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
9820 KB |
Output is correct |
2 |
Correct |
3 ms |
9820 KB |
Output is correct |
3 |
Correct |
3 ms |
9816 KB |
Output is correct |
4 |
Correct |
3 ms |
9820 KB |
Output is correct |
5 |
Correct |
4 ms |
9820 KB |
Output is correct |
6 |
Correct |
3 ms |
9820 KB |
Output is correct |
7 |
Correct |
4 ms |
9820 KB |
Output is correct |
8 |
Correct |
4 ms |
9836 KB |
Output is correct |
9 |
Correct |
3 ms |
9820 KB |
Output is correct |
10 |
Correct |
5 ms |
9852 KB |
Output is correct |
11 |
Correct |
4 ms |
9816 KB |
Output is correct |
12 |
Correct |
3 ms |
10052 KB |
Output is correct |
13 |
Correct |
4 ms |
9884 KB |
Output is correct |
14 |
Correct |
4 ms |
9816 KB |
Output is correct |
15 |
Correct |
4 ms |
9820 KB |
Output is correct |
16 |
Correct |
3 ms |
9820 KB |
Output is correct |
17 |
Correct |
3 ms |
9820 KB |
Output is correct |
18 |
Correct |
4 ms |
9820 KB |
Output is correct |
19 |
Correct |
4 ms |
9820 KB |
Output is correct |
20 |
Correct |
4 ms |
9820 KB |
Output is correct |
21 |
Correct |
4 ms |
9820 KB |
Output is correct |
22 |
Correct |
4 ms |
10000 KB |
Output is correct |
23 |
Correct |
3 ms |
10000 KB |
Output is correct |
24 |
Correct |
5 ms |
9820 KB |
Output is correct |
25 |
Correct |
4 ms |
10020 KB |
Output is correct |
26 |
Correct |
3 ms |
9816 KB |
Output is correct |
27 |
Correct |
5 ms |
9820 KB |
Output is correct |
28 |
Correct |
3 ms |
9820 KB |
Output is correct |
29 |
Correct |
20 ms |
10076 KB |
Output is correct |
30 |
Correct |
24 ms |
10076 KB |
Output is correct |
31 |
Correct |
28 ms |
10072 KB |
Output is correct |
32 |
Correct |
27 ms |
10072 KB |
Output is correct |
33 |
Correct |
35 ms |
10072 KB |
Output is correct |
34 |
Correct |
27 ms |
10076 KB |
Output is correct |
35 |
Correct |
28 ms |
10076 KB |
Output is correct |
36 |
Correct |
19 ms |
10076 KB |
Output is correct |
37 |
Correct |
28 ms |
10168 KB |
Output is correct |
38 |
Correct |
30 ms |
10076 KB |
Output is correct |
39 |
Correct |
21 ms |
10076 KB |
Output is correct |
40 |
Correct |
22 ms |
10072 KB |
Output is correct |
41 |
Correct |
22 ms |
10076 KB |
Output is correct |
42 |
Correct |
21 ms |
10072 KB |
Output is correct |
43 |
Correct |
45 ms |
10076 KB |
Output is correct |
44 |
Correct |
42 ms |
10076 KB |
Output is correct |
45 |
Correct |
40 ms |
10268 KB |
Output is correct |
46 |
Correct |
38 ms |
10076 KB |
Output is correct |
47 |
Correct |
23 ms |
10076 KB |
Output is correct |
48 |
Correct |
25 ms |
10332 KB |
Output is correct |
49 |
Correct |
25 ms |
10076 KB |
Output is correct |
50 |
Correct |
27 ms |
10292 KB |
Output is correct |
51 |
Correct |
28 ms |
10260 KB |
Output is correct |
52 |
Correct |
31 ms |
10324 KB |
Output is correct |
53 |
Correct |
27 ms |
10076 KB |
Output is correct |
54 |
Correct |
28 ms |
10076 KB |
Output is correct |
55 |
Execution timed out |
2019 ms |
31716 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |