# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
395367 |
2021-04-28T09:13:31 Z |
wenqi |
Joker (BOI20_joker) |
C++14 |
|
2000 ms |
21732 KB |
#include <bits/stdc++.h>
using namespace std;
int N, M, Q;
int parents[600069];
int sz[600069];
int ans[600069];
#define ROOT 400
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);
});
int pbl = -1;
int nxt = 0;
for (const R& a : queries) {
int Bs = a.bl * ROOT;
bool doable;
if(a.bl != pbl) {
reset();
doable = false;
for (int i = 1; i < Bs; i++) {
doable |= join(A[i], B[i] + N);
doable |= join(A[i] + N, B[i]);
}
nxt = M;
pbl = a.bl;
}
for(; nxt > a.r; nxt--) {
doable |= join(A[nxt], B[nxt] + N);
doable |= join(A[nxt] + N, B[nxt]);
}
bool k = false;
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;
}
ans[a.i] = k or doable;
for (int i = 0; i < cnt; i++) {
reload();
}
}
for(int i = 0; i < Q; i++) {
cout << (ans[i] ? "YES" : "NO") << '\n';
}
return 0;
}
Compilation message
Joker.cpp: In function 'int main()':
Joker.cpp:114:11: warning: 'doable' may be used uninitialized in this function [-Wmaybe-uninitialized]
114 | doable |= join(A[nxt] + N, B[nxt]);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
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 |
332 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 |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
452 KB |
Output is correct |
28 |
Correct |
2 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 |
332 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 |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
452 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
22 ms |
516 KB |
Output is correct |
30 |
Correct |
24 ms |
544 KB |
Output is correct |
31 |
Correct |
23 ms |
592 KB |
Output is correct |
32 |
Correct |
20 ms |
460 KB |
Output is correct |
33 |
Correct |
20 ms |
460 KB |
Output is correct |
34 |
Correct |
23 ms |
588 KB |
Output is correct |
35 |
Correct |
24 ms |
588 KB |
Output is correct |
36 |
Correct |
18 ms |
588 KB |
Output is correct |
37 |
Correct |
22 ms |
604 KB |
Output is correct |
38 |
Correct |
22 ms |
600 KB |
Output is correct |
39 |
Correct |
24 ms |
468 KB |
Output is correct |
40 |
Correct |
23 ms |
460 KB |
Output is correct |
41 |
Correct |
22 ms |
592 KB |
Output is correct |
42 |
Correct |
22 ms |
592 KB |
Output is correct |
43 |
Correct |
20 ms |
460 KB |
Output is correct |
44 |
Correct |
20 ms |
460 KB |
Output is correct |
45 |
Correct |
26 ms |
588 KB |
Output is correct |
46 |
Correct |
23 ms |
588 KB |
Output is correct |
47 |
Correct |
24 ms |
464 KB |
Output is correct |
48 |
Correct |
20 ms |
460 KB |
Output is correct |
49 |
Correct |
22 ms |
592 KB |
Output is correct |
50 |
Correct |
22 ms |
588 KB |
Output is correct |
51 |
Correct |
21 ms |
460 KB |
Output is correct |
52 |
Correct |
21 ms |
460 KB |
Output is correct |
53 |
Correct |
23 ms |
460 KB |
Output is correct |
54 |
Correct |
24 ms |
600 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 |
139 ms |
15720 KB |
Output is correct |
4 |
Correct |
132 ms |
20812 KB |
Output is correct |
5 |
Correct |
133 ms |
21084 KB |
Output is correct |
6 |
Correct |
124 ms |
19692 KB |
Output is correct |
7 |
Correct |
129 ms |
19644 KB |
Output is correct |
8 |
Correct |
129 ms |
18492 KB |
Output is correct |
9 |
Correct |
124 ms |
19004 KB |
Output is correct |
10 |
Correct |
131 ms |
20764 KB |
Output is correct |
11 |
Correct |
127 ms |
19556 KB |
Output is correct |
12 |
Correct |
128 ms |
21044 KB |
Output is correct |
13 |
Correct |
123 ms |
18332 KB |
Output is correct |
14 |
Correct |
127 ms |
18996 KB |
Output is correct |
15 |
Correct |
133 ms |
20368 KB |
Output is correct |
16 |
Correct |
135 ms |
21300 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 |
332 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 |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
452 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
139 ms |
15720 KB |
Output is correct |
30 |
Correct |
132 ms |
20812 KB |
Output is correct |
31 |
Correct |
133 ms |
21084 KB |
Output is correct |
32 |
Correct |
124 ms |
19692 KB |
Output is correct |
33 |
Correct |
129 ms |
19644 KB |
Output is correct |
34 |
Correct |
129 ms |
18492 KB |
Output is correct |
35 |
Correct |
124 ms |
19004 KB |
Output is correct |
36 |
Correct |
131 ms |
20764 KB |
Output is correct |
37 |
Correct |
127 ms |
19556 KB |
Output is correct |
38 |
Correct |
128 ms |
21044 KB |
Output is correct |
39 |
Correct |
123 ms |
18332 KB |
Output is correct |
40 |
Correct |
127 ms |
18996 KB |
Output is correct |
41 |
Correct |
133 ms |
20368 KB |
Output is correct |
42 |
Correct |
135 ms |
21300 KB |
Output is correct |
43 |
Correct |
1171 ms |
20036 KB |
Output is correct |
44 |
Correct |
1242 ms |
21528 KB |
Output is correct |
45 |
Correct |
1228 ms |
21652 KB |
Output is correct |
46 |
Correct |
1203 ms |
20024 KB |
Output is correct |
47 |
Correct |
1412 ms |
20052 KB |
Output is correct |
48 |
Correct |
1318 ms |
19660 KB |
Output is correct |
49 |
Correct |
1408 ms |
21276 KB |
Output is correct |
50 |
Correct |
1098 ms |
19592 KB |
Output is correct |
51 |
Correct |
1248 ms |
20856 KB |
Output is correct |
52 |
Correct |
1267 ms |
21732 KB |
Output is correct |
53 |
Correct |
1114 ms |
18564 KB |
Output is correct |
54 |
Correct |
1487 ms |
19608 KB |
Output is correct |
55 |
Correct |
1552 ms |
20704 KB |
Output is correct |
56 |
Correct |
1586 ms |
21616 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 |
332 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 |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
452 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
22 ms |
516 KB |
Output is correct |
30 |
Correct |
24 ms |
544 KB |
Output is correct |
31 |
Correct |
23 ms |
592 KB |
Output is correct |
32 |
Correct |
20 ms |
460 KB |
Output is correct |
33 |
Correct |
20 ms |
460 KB |
Output is correct |
34 |
Correct |
23 ms |
588 KB |
Output is correct |
35 |
Correct |
24 ms |
588 KB |
Output is correct |
36 |
Correct |
18 ms |
588 KB |
Output is correct |
37 |
Correct |
22 ms |
604 KB |
Output is correct |
38 |
Correct |
22 ms |
600 KB |
Output is correct |
39 |
Correct |
24 ms |
468 KB |
Output is correct |
40 |
Correct |
23 ms |
460 KB |
Output is correct |
41 |
Correct |
22 ms |
592 KB |
Output is correct |
42 |
Correct |
22 ms |
592 KB |
Output is correct |
43 |
Correct |
20 ms |
460 KB |
Output is correct |
44 |
Correct |
20 ms |
460 KB |
Output is correct |
45 |
Correct |
26 ms |
588 KB |
Output is correct |
46 |
Correct |
23 ms |
588 KB |
Output is correct |
47 |
Correct |
24 ms |
464 KB |
Output is correct |
48 |
Correct |
20 ms |
460 KB |
Output is correct |
49 |
Correct |
22 ms |
592 KB |
Output is correct |
50 |
Correct |
22 ms |
588 KB |
Output is correct |
51 |
Correct |
21 ms |
460 KB |
Output is correct |
52 |
Correct |
21 ms |
460 KB |
Output is correct |
53 |
Correct |
23 ms |
460 KB |
Output is correct |
54 |
Correct |
24 ms |
600 KB |
Output is correct |
55 |
Execution timed out |
2086 ms |
14192 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 |
332 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 |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
452 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
22 ms |
516 KB |
Output is correct |
30 |
Correct |
24 ms |
544 KB |
Output is correct |
31 |
Correct |
23 ms |
592 KB |
Output is correct |
32 |
Correct |
20 ms |
460 KB |
Output is correct |
33 |
Correct |
20 ms |
460 KB |
Output is correct |
34 |
Correct |
23 ms |
588 KB |
Output is correct |
35 |
Correct |
24 ms |
588 KB |
Output is correct |
36 |
Correct |
18 ms |
588 KB |
Output is correct |
37 |
Correct |
22 ms |
604 KB |
Output is correct |
38 |
Correct |
22 ms |
600 KB |
Output is correct |
39 |
Correct |
24 ms |
468 KB |
Output is correct |
40 |
Correct |
23 ms |
460 KB |
Output is correct |
41 |
Correct |
22 ms |
592 KB |
Output is correct |
42 |
Correct |
22 ms |
592 KB |
Output is correct |
43 |
Correct |
20 ms |
460 KB |
Output is correct |
44 |
Correct |
20 ms |
460 KB |
Output is correct |
45 |
Correct |
26 ms |
588 KB |
Output is correct |
46 |
Correct |
23 ms |
588 KB |
Output is correct |
47 |
Correct |
24 ms |
464 KB |
Output is correct |
48 |
Correct |
20 ms |
460 KB |
Output is correct |
49 |
Correct |
22 ms |
592 KB |
Output is correct |
50 |
Correct |
22 ms |
588 KB |
Output is correct |
51 |
Correct |
21 ms |
460 KB |
Output is correct |
52 |
Correct |
21 ms |
460 KB |
Output is correct |
53 |
Correct |
23 ms |
460 KB |
Output is correct |
54 |
Correct |
24 ms |
600 KB |
Output is correct |
55 |
Correct |
139 ms |
15720 KB |
Output is correct |
56 |
Correct |
132 ms |
20812 KB |
Output is correct |
57 |
Correct |
133 ms |
21084 KB |
Output is correct |
58 |
Correct |
124 ms |
19692 KB |
Output is correct |
59 |
Correct |
129 ms |
19644 KB |
Output is correct |
60 |
Correct |
129 ms |
18492 KB |
Output is correct |
61 |
Correct |
124 ms |
19004 KB |
Output is correct |
62 |
Correct |
131 ms |
20764 KB |
Output is correct |
63 |
Correct |
127 ms |
19556 KB |
Output is correct |
64 |
Correct |
128 ms |
21044 KB |
Output is correct |
65 |
Correct |
123 ms |
18332 KB |
Output is correct |
66 |
Correct |
127 ms |
18996 KB |
Output is correct |
67 |
Correct |
133 ms |
20368 KB |
Output is correct |
68 |
Correct |
135 ms |
21300 KB |
Output is correct |
69 |
Correct |
1171 ms |
20036 KB |
Output is correct |
70 |
Correct |
1242 ms |
21528 KB |
Output is correct |
71 |
Correct |
1228 ms |
21652 KB |
Output is correct |
72 |
Correct |
1203 ms |
20024 KB |
Output is correct |
73 |
Correct |
1412 ms |
20052 KB |
Output is correct |
74 |
Correct |
1318 ms |
19660 KB |
Output is correct |
75 |
Correct |
1408 ms |
21276 KB |
Output is correct |
76 |
Correct |
1098 ms |
19592 KB |
Output is correct |
77 |
Correct |
1248 ms |
20856 KB |
Output is correct |
78 |
Correct |
1267 ms |
21732 KB |
Output is correct |
79 |
Correct |
1114 ms |
18564 KB |
Output is correct |
80 |
Correct |
1487 ms |
19608 KB |
Output is correct |
81 |
Correct |
1552 ms |
20704 KB |
Output is correct |
82 |
Correct |
1586 ms |
21616 KB |
Output is correct |
83 |
Execution timed out |
2086 ms |
14192 KB |
Time limit exceeded |
84 |
Halted |
0 ms |
0 KB |
- |