# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
396483 |
2021-04-30T03:25:44 Z |
wenqi |
Joker (BOI20_joker) |
C++14 |
|
2000 ms |
21608 KB |
#include <bits/stdc++.h>
using namespace std;
int N, M, Q;
int parents[600069];
int sz[600069];
int ans[600069];
#define ROOT 40
struct E {
int i, a;
int j, b;
};
struct R {
int i, l, r, bl;
};
vector<E> moves;
void reset() {
for (int i = 0; i < 2 * N; i++) {
parents[i] = i;
sz[i] = 1;
}
moves.clear();
}
int getp(int i) {
return i == parents[i] ? i : getp(parents[i]);
}
bool join(int a, int b) {
a = getp(a);
b = getp(b);
if(a == b) {
moves.push_back({-1});
return false;
}
if(sz[a] > sz[b]) {
moves.push_back({b, parents[b], a, sz[a]});
parents[b] = a;
sz[a] += sz[b];
}else{
moves.push_back({a, parents[a], b, sz[b]});
parents[a] = b;
sz[b] += sz[a];
}
return getp(a) == getp((a + N) % (2 * N)) or getp(b) == getp((b + N) % (2 * N));
}
void reload() {
auto p = moves.back();
moves.pop_back();
if(p.i == -1)
return;
parents[p.i] = p.a;
sz[p.j] = p.b;
}
int A[200069];
int B[200069];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M >> Q;
for (int i = 1; i <= M; i++) {
int a, b;
cin >> a >> b;
A[i] = --a;
B[i] = --b;
}
vector<R> queries;
for (int i = 0; i < Q; i++) {
int l, r;
cin >> l >> r;
queries.push_back({i, l, r, l / ROOT});
}
sort(queries.begin(), queries.end(), [](R& a, R& b) {
return a.bl < b.bl or (a.bl == b.bl and a.r > b.r);
});
bool made = false;
int pbl = -1;
int nxt = 0;
int up = 0;
int start = 1;
bool doable = false;
reset();
for (const R& a : queries) {
int Bs = a.bl * ROOT;
if(a.bl != pbl) {
doable = false;
for(int i = 0; i < up; i++) {
reload();
}
up = 0;
if(not made) {
for (; start < Bs; start++) {
made |= join(A[start], B[start] + N);
made |= join(A[start] + N, B[start]);
}
}
nxt = M;
pbl = a.bl;
}
if(not made and not doable) {
for(; nxt > a.r; nxt--) {
doable |= join(A[nxt], B[nxt] + N);
doable |= join(A[nxt] + N, B[nxt]);
up += 2;
}
}
bool k = false;
if (not made and not doable) {
int cnt = 0;
for (int i = Bs; i < a.l; i++) {
if(i == 0) continue;
k |= join(A[i], B[i] + N);
k |= join(A[i] + N, B[i]);
cnt += 2;
}
for (int i = 0; i < cnt; i++) {
reload();
}
}
ans[a.i] = made or doable or k;
}
for(int i = 0; i < Q; i++) {
cout << (ans[i] ? "YES" : "NO") << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
5 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
588 KB |
Output is correct |
31 |
Correct |
4 ms |
588 KB |
Output is correct |
32 |
Correct |
3 ms |
460 KB |
Output is correct |
33 |
Correct |
2 ms |
460 KB |
Output is correct |
34 |
Correct |
3 ms |
588 KB |
Output is correct |
35 |
Correct |
4 ms |
588 KB |
Output is correct |
36 |
Correct |
3 ms |
592 KB |
Output is correct |
37 |
Correct |
7 ms |
588 KB |
Output is correct |
38 |
Correct |
7 ms |
588 KB |
Output is correct |
39 |
Correct |
5 ms |
588 KB |
Output is correct |
40 |
Correct |
3 ms |
524 KB |
Output is correct |
41 |
Correct |
4 ms |
464 KB |
Output is correct |
42 |
Correct |
4 ms |
460 KB |
Output is correct |
43 |
Correct |
2 ms |
460 KB |
Output is correct |
44 |
Correct |
3 ms |
588 KB |
Output is correct |
45 |
Correct |
2 ms |
576 KB |
Output is correct |
46 |
Correct |
3 ms |
588 KB |
Output is correct |
47 |
Correct |
3 ms |
460 KB |
Output is correct |
48 |
Correct |
3 ms |
460 KB |
Output is correct |
49 |
Correct |
3 ms |
568 KB |
Output is correct |
50 |
Correct |
4 ms |
588 KB |
Output is correct |
51 |
Correct |
3 ms |
460 KB |
Output is correct |
52 |
Correct |
4 ms |
460 KB |
Output is correct |
53 |
Correct |
4 ms |
520 KB |
Output is correct |
54 |
Correct |
4 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
114 ms |
17536 KB |
Output is correct |
4 |
Correct |
126 ms |
20780 KB |
Output is correct |
5 |
Correct |
107 ms |
15068 KB |
Output is correct |
6 |
Correct |
111 ms |
17456 KB |
Output is correct |
7 |
Correct |
113 ms |
17484 KB |
Output is correct |
8 |
Correct |
107 ms |
16128 KB |
Output is correct |
9 |
Correct |
108 ms |
16836 KB |
Output is correct |
10 |
Correct |
121 ms |
18612 KB |
Output is correct |
11 |
Correct |
116 ms |
17416 KB |
Output is correct |
12 |
Correct |
118 ms |
18880 KB |
Output is correct |
13 |
Correct |
113 ms |
16056 KB |
Output is correct |
14 |
Correct |
119 ms |
17180 KB |
Output is correct |
15 |
Correct |
120 ms |
18096 KB |
Output is correct |
16 |
Correct |
145 ms |
19176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
114 ms |
17536 KB |
Output is correct |
30 |
Correct |
126 ms |
20780 KB |
Output is correct |
31 |
Correct |
107 ms |
15068 KB |
Output is correct |
32 |
Correct |
111 ms |
17456 KB |
Output is correct |
33 |
Correct |
113 ms |
17484 KB |
Output is correct |
34 |
Correct |
107 ms |
16128 KB |
Output is correct |
35 |
Correct |
108 ms |
16836 KB |
Output is correct |
36 |
Correct |
121 ms |
18612 KB |
Output is correct |
37 |
Correct |
116 ms |
17416 KB |
Output is correct |
38 |
Correct |
118 ms |
18880 KB |
Output is correct |
39 |
Correct |
113 ms |
16056 KB |
Output is correct |
40 |
Correct |
119 ms |
17180 KB |
Output is correct |
41 |
Correct |
120 ms |
18096 KB |
Output is correct |
42 |
Correct |
145 ms |
19176 KB |
Output is correct |
43 |
Correct |
337 ms |
17856 KB |
Output is correct |
44 |
Correct |
439 ms |
21296 KB |
Output is correct |
45 |
Correct |
414 ms |
21608 KB |
Output is correct |
46 |
Correct |
267 ms |
17844 KB |
Output is correct |
47 |
Correct |
290 ms |
17736 KB |
Output is correct |
48 |
Correct |
168 ms |
17300 KB |
Output is correct |
49 |
Correct |
222 ms |
19104 KB |
Output is correct |
50 |
Correct |
301 ms |
17396 KB |
Output is correct |
51 |
Correct |
325 ms |
18536 KB |
Output is correct |
52 |
Correct |
350 ms |
19384 KB |
Output is correct |
53 |
Correct |
262 ms |
16428 KB |
Output is correct |
54 |
Correct |
342 ms |
17444 KB |
Output is correct |
55 |
Correct |
362 ms |
18484 KB |
Output is correct |
56 |
Correct |
391 ms |
19460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
5 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
588 KB |
Output is correct |
31 |
Correct |
4 ms |
588 KB |
Output is correct |
32 |
Correct |
3 ms |
460 KB |
Output is correct |
33 |
Correct |
2 ms |
460 KB |
Output is correct |
34 |
Correct |
3 ms |
588 KB |
Output is correct |
35 |
Correct |
4 ms |
588 KB |
Output is correct |
36 |
Correct |
3 ms |
592 KB |
Output is correct |
37 |
Correct |
7 ms |
588 KB |
Output is correct |
38 |
Correct |
7 ms |
588 KB |
Output is correct |
39 |
Correct |
5 ms |
588 KB |
Output is correct |
40 |
Correct |
3 ms |
524 KB |
Output is correct |
41 |
Correct |
4 ms |
464 KB |
Output is correct |
42 |
Correct |
4 ms |
460 KB |
Output is correct |
43 |
Correct |
2 ms |
460 KB |
Output is correct |
44 |
Correct |
3 ms |
588 KB |
Output is correct |
45 |
Correct |
2 ms |
576 KB |
Output is correct |
46 |
Correct |
3 ms |
588 KB |
Output is correct |
47 |
Correct |
3 ms |
460 KB |
Output is correct |
48 |
Correct |
3 ms |
460 KB |
Output is correct |
49 |
Correct |
3 ms |
568 KB |
Output is correct |
50 |
Correct |
4 ms |
588 KB |
Output is correct |
51 |
Correct |
3 ms |
460 KB |
Output is correct |
52 |
Correct |
4 ms |
460 KB |
Output is correct |
53 |
Correct |
4 ms |
520 KB |
Output is correct |
54 |
Correct |
4 ms |
592 KB |
Output is correct |
55 |
Execution timed out |
2079 ms |
14176 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
5 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
588 KB |
Output is correct |
31 |
Correct |
4 ms |
588 KB |
Output is correct |
32 |
Correct |
3 ms |
460 KB |
Output is correct |
33 |
Correct |
2 ms |
460 KB |
Output is correct |
34 |
Correct |
3 ms |
588 KB |
Output is correct |
35 |
Correct |
4 ms |
588 KB |
Output is correct |
36 |
Correct |
3 ms |
592 KB |
Output is correct |
37 |
Correct |
7 ms |
588 KB |
Output is correct |
38 |
Correct |
7 ms |
588 KB |
Output is correct |
39 |
Correct |
5 ms |
588 KB |
Output is correct |
40 |
Correct |
3 ms |
524 KB |
Output is correct |
41 |
Correct |
4 ms |
464 KB |
Output is correct |
42 |
Correct |
4 ms |
460 KB |
Output is correct |
43 |
Correct |
2 ms |
460 KB |
Output is correct |
44 |
Correct |
3 ms |
588 KB |
Output is correct |
45 |
Correct |
2 ms |
576 KB |
Output is correct |
46 |
Correct |
3 ms |
588 KB |
Output is correct |
47 |
Correct |
3 ms |
460 KB |
Output is correct |
48 |
Correct |
3 ms |
460 KB |
Output is correct |
49 |
Correct |
3 ms |
568 KB |
Output is correct |
50 |
Correct |
4 ms |
588 KB |
Output is correct |
51 |
Correct |
3 ms |
460 KB |
Output is correct |
52 |
Correct |
4 ms |
460 KB |
Output is correct |
53 |
Correct |
4 ms |
520 KB |
Output is correct |
54 |
Correct |
4 ms |
592 KB |
Output is correct |
55 |
Correct |
114 ms |
17536 KB |
Output is correct |
56 |
Correct |
126 ms |
20780 KB |
Output is correct |
57 |
Correct |
107 ms |
15068 KB |
Output is correct |
58 |
Correct |
111 ms |
17456 KB |
Output is correct |
59 |
Correct |
113 ms |
17484 KB |
Output is correct |
60 |
Correct |
107 ms |
16128 KB |
Output is correct |
61 |
Correct |
108 ms |
16836 KB |
Output is correct |
62 |
Correct |
121 ms |
18612 KB |
Output is correct |
63 |
Correct |
116 ms |
17416 KB |
Output is correct |
64 |
Correct |
118 ms |
18880 KB |
Output is correct |
65 |
Correct |
113 ms |
16056 KB |
Output is correct |
66 |
Correct |
119 ms |
17180 KB |
Output is correct |
67 |
Correct |
120 ms |
18096 KB |
Output is correct |
68 |
Correct |
145 ms |
19176 KB |
Output is correct |
69 |
Correct |
337 ms |
17856 KB |
Output is correct |
70 |
Correct |
439 ms |
21296 KB |
Output is correct |
71 |
Correct |
414 ms |
21608 KB |
Output is correct |
72 |
Correct |
267 ms |
17844 KB |
Output is correct |
73 |
Correct |
290 ms |
17736 KB |
Output is correct |
74 |
Correct |
168 ms |
17300 KB |
Output is correct |
75 |
Correct |
222 ms |
19104 KB |
Output is correct |
76 |
Correct |
301 ms |
17396 KB |
Output is correct |
77 |
Correct |
325 ms |
18536 KB |
Output is correct |
78 |
Correct |
350 ms |
19384 KB |
Output is correct |
79 |
Correct |
262 ms |
16428 KB |
Output is correct |
80 |
Correct |
342 ms |
17444 KB |
Output is correct |
81 |
Correct |
362 ms |
18484 KB |
Output is correct |
82 |
Correct |
391 ms |
19460 KB |
Output is correct |
83 |
Execution timed out |
2079 ms |
14176 KB |
Time limit exceeded |
84 |
Halted |
0 ms |
0 KB |
- |