#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,bmi,bmi2,lzcnt,popcnt")
using pii = pair<int, int>;
struct DSU {
int n, P;
vector<pii> par;
vector<int> size, bi;
vector<pair<int&, int> > st;
void init(int _n, int _P) {
n = _n + 1;
P = _P;
par.resize(n+1);
size.resize(n+1, 1);
bi.resize(n+1, 1);
for(int i=1; i<=n; i++) par[i] = { i, 0 };
}
pii find(int u) {
if(u == par[u].first) return par[u];
int p = par[u].second;
if(P) {
auto p2 = find(par[u].first);
return { p2.first, p2.second ^ p };
}
par[u] = find(par[u].first);
par[u].second ^= p;
return par[u];
}
bool uni(int a, int b) {
pii pa = find(a), pb = find(b);
if(P) st.push_back({ bi[pa.first], bi[pb.first] });
if(pa.first == pb.first) {
if(pa.second == pb.second) bi[pa.first] = 0;
return 0;
}
if(size[pa.first] < size[pb.first]) swap(pa, pb);
if(P) {
st.push_back({ size[pa.first], size[pa.first] });
st.push_back({ par[pa.first].first, par[pa.first].first });
st.push_back({ par[pa.first].second, par[pa.first].second });
}
size[pa.first] += size[pb.first];
par[pb.first] = { pa.first, pa.second ^ pb.second ^ 1 };
bi[pa.first] &= bi[pb.first];
return 1;
}
void roll(int sz) {
while(st.size() > sz) {
st.back().first = st.back().second;
st.pop_back();
}
}
int snap() { return st.size(); }
int getBi(int u) { return bi[find(u).first]; }
};
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
vector<array<int, 2> > edges(m);
for(auto &[a, b] : edges) cin >> a >> b;
if(n <= 2000 && m <= 2000 && q <= 2000) {
while(q--) {
int l, r, ans = 1;
cin >> l >> r;
l--, r--;
DSU dsu; dsu.init(n, 0);
for(int i=0; i<m; i++) {
if(i >= l && i <= r) continue;
dsu.uni(edges[i][0], edges[i][1]);
if(!dsu.getBi(edges[i][0])) {
ans = 0;
break;
}
}
cout << (!ans ? "YES" : "NO") << '\n';
}
return 0;
}
vector<pii> qus[m];
for(int i=0; i<q; i++) {
int l, r;
cin >> l >> r;
qus[l-1].push_back({ r-1, i });
}
vector<bool> ans(q);
for(int it=0; it<200; it++) {
if(qus[it].empty()) continue;
sort(qus[it].rbegin(), qus[it].rend());
int p = 0, ok = 1;
DSU dsu; dsu.init(n, 0);
for(int i=0; i<it; i++) {
dsu.uni(edges[i][0], edges[i][1]);
if(!dsu.getBi(edges[i][0])) ok = 0;
}
for(int i=m-1; i>=0&&ok; i--) {
while(p < qus[it].size() && qus[it][p].first == i) {
ans[qus[it][p].second] = ok;
p++;
}
dsu.uni(edges[i][0], edges[i][1]);
if(!dsu.getBi(edges[i][0])) ok = 0;
}
}
for(int i=0; i<q; i++)
cout << (!ans[i] ? "YES" : "NO") << '\n';
return 0;
}
Compilation message
Joker.cpp: In member function 'void DSU::roll(int)':
Joker.cpp:63:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int&, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
63 | while(st.size() > sz) {
| ~~~~~~~~~~^~~~
Joker.cpp: In function 'int main()':
Joker.cpp:125:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
125 | while(p < qus[it].size() && qus[it][p].first == i) {
| ~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
456 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
456 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
28 ms |
344 KB |
Output is correct |
30 |
Correct |
38 ms |
504 KB |
Output is correct |
31 |
Correct |
30 ms |
348 KB |
Output is correct |
32 |
Correct |
18 ms |
524 KB |
Output is correct |
33 |
Correct |
11 ms |
520 KB |
Output is correct |
34 |
Correct |
24 ms |
540 KB |
Output is correct |
35 |
Correct |
61 ms |
348 KB |
Output is correct |
36 |
Correct |
28 ms |
524 KB |
Output is correct |
37 |
Correct |
73 ms |
348 KB |
Output is correct |
38 |
Correct |
64 ms |
348 KB |
Output is correct |
39 |
Correct |
43 ms |
604 KB |
Output is correct |
40 |
Correct |
30 ms |
344 KB |
Output is correct |
41 |
Correct |
32 ms |
344 KB |
Output is correct |
42 |
Correct |
26 ms |
600 KB |
Output is correct |
43 |
Correct |
28 ms |
348 KB |
Output is correct |
44 |
Correct |
36 ms |
344 KB |
Output is correct |
45 |
Correct |
29 ms |
348 KB |
Output is correct |
46 |
Correct |
32 ms |
344 KB |
Output is correct |
47 |
Correct |
27 ms |
348 KB |
Output is correct |
48 |
Correct |
28 ms |
524 KB |
Output is correct |
49 |
Correct |
30 ms |
348 KB |
Output is correct |
50 |
Correct |
42 ms |
348 KB |
Output is correct |
51 |
Correct |
26 ms |
348 KB |
Output is correct |
52 |
Correct |
28 ms |
472 KB |
Output is correct |
53 |
Correct |
29 ms |
528 KB |
Output is correct |
54 |
Correct |
34 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
63 ms |
14284 KB |
Output is correct |
4 |
Correct |
81 ms |
14792 KB |
Output is correct |
5 |
Correct |
71 ms |
15232 KB |
Output is correct |
6 |
Correct |
69 ms |
14416 KB |
Output is correct |
7 |
Correct |
71 ms |
14644 KB |
Output is correct |
8 |
Correct |
65 ms |
13256 KB |
Output is correct |
9 |
Correct |
68 ms |
13768 KB |
Output is correct |
10 |
Correct |
67 ms |
14792 KB |
Output is correct |
11 |
Correct |
69 ms |
14284 KB |
Output is correct |
12 |
Correct |
77 ms |
15112 KB |
Output is correct |
13 |
Correct |
69 ms |
12880 KB |
Output is correct |
14 |
Correct |
74 ms |
13772 KB |
Output is correct |
15 |
Correct |
72 ms |
14288 KB |
Output is correct |
16 |
Correct |
70 ms |
15304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
456 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
63 ms |
14284 KB |
Output is correct |
30 |
Correct |
81 ms |
14792 KB |
Output is correct |
31 |
Correct |
71 ms |
15232 KB |
Output is correct |
32 |
Correct |
69 ms |
14416 KB |
Output is correct |
33 |
Correct |
71 ms |
14644 KB |
Output is correct |
34 |
Correct |
65 ms |
13256 KB |
Output is correct |
35 |
Correct |
68 ms |
13768 KB |
Output is correct |
36 |
Correct |
67 ms |
14792 KB |
Output is correct |
37 |
Correct |
69 ms |
14284 KB |
Output is correct |
38 |
Correct |
77 ms |
15112 KB |
Output is correct |
39 |
Correct |
69 ms |
12880 KB |
Output is correct |
40 |
Correct |
74 ms |
13772 KB |
Output is correct |
41 |
Correct |
72 ms |
14288 KB |
Output is correct |
42 |
Correct |
70 ms |
15304 KB |
Output is correct |
43 |
Correct |
704 ms |
15000 KB |
Output is correct |
44 |
Correct |
1648 ms |
16168 KB |
Output is correct |
45 |
Correct |
1289 ms |
16408 KB |
Output is correct |
46 |
Correct |
196 ms |
14996 KB |
Output is correct |
47 |
Correct |
236 ms |
14844 KB |
Output is correct |
48 |
Correct |
488 ms |
14312 KB |
Output is correct |
49 |
Correct |
872 ms |
16176 KB |
Output is correct |
50 |
Correct |
748 ms |
14716 KB |
Output is correct |
51 |
Correct |
785 ms |
15592 KB |
Output is correct |
52 |
Correct |
812 ms |
16696 KB |
Output is correct |
53 |
Correct |
316 ms |
13676 KB |
Output is correct |
54 |
Correct |
458 ms |
14588 KB |
Output is correct |
55 |
Correct |
693 ms |
15664 KB |
Output is correct |
56 |
Correct |
878 ms |
16772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
456 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
28 ms |
344 KB |
Output is correct |
30 |
Correct |
38 ms |
504 KB |
Output is correct |
31 |
Correct |
30 ms |
348 KB |
Output is correct |
32 |
Correct |
18 ms |
524 KB |
Output is correct |
33 |
Correct |
11 ms |
520 KB |
Output is correct |
34 |
Correct |
24 ms |
540 KB |
Output is correct |
35 |
Correct |
61 ms |
348 KB |
Output is correct |
36 |
Correct |
28 ms |
524 KB |
Output is correct |
37 |
Correct |
73 ms |
348 KB |
Output is correct |
38 |
Correct |
64 ms |
348 KB |
Output is correct |
39 |
Correct |
43 ms |
604 KB |
Output is correct |
40 |
Correct |
30 ms |
344 KB |
Output is correct |
41 |
Correct |
32 ms |
344 KB |
Output is correct |
42 |
Correct |
26 ms |
600 KB |
Output is correct |
43 |
Correct |
28 ms |
348 KB |
Output is correct |
44 |
Correct |
36 ms |
344 KB |
Output is correct |
45 |
Correct |
29 ms |
348 KB |
Output is correct |
46 |
Correct |
32 ms |
344 KB |
Output is correct |
47 |
Correct |
27 ms |
348 KB |
Output is correct |
48 |
Correct |
28 ms |
524 KB |
Output is correct |
49 |
Correct |
30 ms |
348 KB |
Output is correct |
50 |
Correct |
42 ms |
348 KB |
Output is correct |
51 |
Correct |
26 ms |
348 KB |
Output is correct |
52 |
Correct |
28 ms |
472 KB |
Output is correct |
53 |
Correct |
29 ms |
528 KB |
Output is correct |
54 |
Correct |
34 ms |
544 KB |
Output is correct |
55 |
Incorrect |
26 ms |
10588 KB |
Output isn't correct |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
456 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
28 ms |
344 KB |
Output is correct |
30 |
Correct |
38 ms |
504 KB |
Output is correct |
31 |
Correct |
30 ms |
348 KB |
Output is correct |
32 |
Correct |
18 ms |
524 KB |
Output is correct |
33 |
Correct |
11 ms |
520 KB |
Output is correct |
34 |
Correct |
24 ms |
540 KB |
Output is correct |
35 |
Correct |
61 ms |
348 KB |
Output is correct |
36 |
Correct |
28 ms |
524 KB |
Output is correct |
37 |
Correct |
73 ms |
348 KB |
Output is correct |
38 |
Correct |
64 ms |
348 KB |
Output is correct |
39 |
Correct |
43 ms |
604 KB |
Output is correct |
40 |
Correct |
30 ms |
344 KB |
Output is correct |
41 |
Correct |
32 ms |
344 KB |
Output is correct |
42 |
Correct |
26 ms |
600 KB |
Output is correct |
43 |
Correct |
28 ms |
348 KB |
Output is correct |
44 |
Correct |
36 ms |
344 KB |
Output is correct |
45 |
Correct |
29 ms |
348 KB |
Output is correct |
46 |
Correct |
32 ms |
344 KB |
Output is correct |
47 |
Correct |
27 ms |
348 KB |
Output is correct |
48 |
Correct |
28 ms |
524 KB |
Output is correct |
49 |
Correct |
30 ms |
348 KB |
Output is correct |
50 |
Correct |
42 ms |
348 KB |
Output is correct |
51 |
Correct |
26 ms |
348 KB |
Output is correct |
52 |
Correct |
28 ms |
472 KB |
Output is correct |
53 |
Correct |
29 ms |
528 KB |
Output is correct |
54 |
Correct |
34 ms |
544 KB |
Output is correct |
55 |
Correct |
63 ms |
14284 KB |
Output is correct |
56 |
Correct |
81 ms |
14792 KB |
Output is correct |
57 |
Correct |
71 ms |
15232 KB |
Output is correct |
58 |
Correct |
69 ms |
14416 KB |
Output is correct |
59 |
Correct |
71 ms |
14644 KB |
Output is correct |
60 |
Correct |
65 ms |
13256 KB |
Output is correct |
61 |
Correct |
68 ms |
13768 KB |
Output is correct |
62 |
Correct |
67 ms |
14792 KB |
Output is correct |
63 |
Correct |
69 ms |
14284 KB |
Output is correct |
64 |
Correct |
77 ms |
15112 KB |
Output is correct |
65 |
Correct |
69 ms |
12880 KB |
Output is correct |
66 |
Correct |
74 ms |
13772 KB |
Output is correct |
67 |
Correct |
72 ms |
14288 KB |
Output is correct |
68 |
Correct |
70 ms |
15304 KB |
Output is correct |
69 |
Correct |
704 ms |
15000 KB |
Output is correct |
70 |
Correct |
1648 ms |
16168 KB |
Output is correct |
71 |
Correct |
1289 ms |
16408 KB |
Output is correct |
72 |
Correct |
196 ms |
14996 KB |
Output is correct |
73 |
Correct |
236 ms |
14844 KB |
Output is correct |
74 |
Correct |
488 ms |
14312 KB |
Output is correct |
75 |
Correct |
872 ms |
16176 KB |
Output is correct |
76 |
Correct |
748 ms |
14716 KB |
Output is correct |
77 |
Correct |
785 ms |
15592 KB |
Output is correct |
78 |
Correct |
812 ms |
16696 KB |
Output is correct |
79 |
Correct |
316 ms |
13676 KB |
Output is correct |
80 |
Correct |
458 ms |
14588 KB |
Output is correct |
81 |
Correct |
693 ms |
15664 KB |
Output is correct |
82 |
Correct |
878 ms |
16772 KB |
Output is correct |
83 |
Incorrect |
26 ms |
10588 KB |
Output isn't correct |
84 |
Halted |
0 ms |
0 KB |
- |