#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define N 200100
vector<int> adj[N];
vector<pair<int, int>> arr[N];
int color[N], ans[N], a[N], b[N], n, m, q;
int dfs(int x, int col) {
if(color[x]) {
if(col==color[x]) return 0;
else return 1;
}
color[x] = col;
for(auto i: adj[x])
if(dfs(i, 3-col))
return 1;
return 0;
}
bool check(int l, int r) {
memset(color, 0, sizeof color);
for(int i = 1; i <= n; i++)
adj[i].clear();
for(int i = 0; i < l; i++)
adj[a[i]].push_back(b[i]), adj[b[i]].push_back(a[i]);
for(int i = r+1; i < m; i++)
adj[a[i]].push_back(b[i]), adj[b[i]].push_back(a[i]);
for(int i = 0; i < n; i++)
if(!color[i])
if(dfs(i, 1))
return 1;
return 0;
}
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> q;
for(int i = 0; i < m; i++)
cin >> a[i] >> b[i];
for(int i = 0; i < q; ++i) {
int l, r;
cin >> l >> r;
arr[l-1].push_back({r-1,i});
}
for(int i = 0; i < m; i++) {
sort(arr[i].begin(), arr[i].end());
int l = 0, r = arr[i].size();
while(l<r) {
int mid = l+r>>1;
if(check(i, arr[i][mid].first)) {
l = mid+1;
} else {
r = mid;
}
}
for(int j = 0; j < l; j++)
ans[arr[i][j].second] = 1;
for(int j = l; j < arr[i].size(); ++j)
ans[arr[i][j].second] = 0;
}
for(int i = 0; i < q; i++)
cout << (ans[i]?"YES\n":"NO\n");
}
Compilation message
Joker.cpp: In function 'int main()':
Joker.cpp:48:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
48 | int mid = l+r>>1;
| ~^~
Joker.cpp:57:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int j = l; j < arr[i].size(); ++j)
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
10452 KB |
Output is correct |
2 |
Correct |
4 ms |
10452 KB |
Output is correct |
3 |
Correct |
4 ms |
10452 KB |
Output is correct |
4 |
Correct |
4 ms |
10452 KB |
Output is correct |
5 |
Correct |
4 ms |
10452 KB |
Output is correct |
6 |
Correct |
4 ms |
10452 KB |
Output is correct |
7 |
Correct |
6 ms |
10452 KB |
Output is correct |
8 |
Correct |
7 ms |
10536 KB |
Output is correct |
9 |
Correct |
8 ms |
10432 KB |
Output is correct |
10 |
Correct |
7 ms |
10452 KB |
Output is correct |
11 |
Correct |
9 ms |
10580 KB |
Output is correct |
12 |
Correct |
7 ms |
10452 KB |
Output is correct |
13 |
Correct |
6 ms |
10452 KB |
Output is correct |
14 |
Correct |
7 ms |
10452 KB |
Output is correct |
15 |
Correct |
7 ms |
10452 KB |
Output is correct |
16 |
Correct |
7 ms |
10452 KB |
Output is correct |
17 |
Correct |
7 ms |
10468 KB |
Output is correct |
18 |
Correct |
7 ms |
10528 KB |
Output is correct |
19 |
Correct |
8 ms |
10452 KB |
Output is correct |
20 |
Correct |
7 ms |
10452 KB |
Output is correct |
21 |
Correct |
6 ms |
10452 KB |
Output is correct |
22 |
Correct |
7 ms |
10452 KB |
Output is correct |
23 |
Correct |
7 ms |
10532 KB |
Output is correct |
24 |
Correct |
7 ms |
10452 KB |
Output is correct |
25 |
Correct |
6 ms |
10516 KB |
Output is correct |
26 |
Correct |
7 ms |
10452 KB |
Output is correct |
27 |
Correct |
7 ms |
10452 KB |
Output is correct |
28 |
Correct |
7 ms |
10452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
10452 KB |
Output is correct |
2 |
Correct |
4 ms |
10452 KB |
Output is correct |
3 |
Correct |
4 ms |
10452 KB |
Output is correct |
4 |
Correct |
4 ms |
10452 KB |
Output is correct |
5 |
Correct |
4 ms |
10452 KB |
Output is correct |
6 |
Correct |
4 ms |
10452 KB |
Output is correct |
7 |
Correct |
6 ms |
10452 KB |
Output is correct |
8 |
Correct |
7 ms |
10536 KB |
Output is correct |
9 |
Correct |
8 ms |
10432 KB |
Output is correct |
10 |
Correct |
7 ms |
10452 KB |
Output is correct |
11 |
Correct |
9 ms |
10580 KB |
Output is correct |
12 |
Correct |
7 ms |
10452 KB |
Output is correct |
13 |
Correct |
6 ms |
10452 KB |
Output is correct |
14 |
Correct |
7 ms |
10452 KB |
Output is correct |
15 |
Correct |
7 ms |
10452 KB |
Output is correct |
16 |
Correct |
7 ms |
10452 KB |
Output is correct |
17 |
Correct |
7 ms |
10468 KB |
Output is correct |
18 |
Correct |
7 ms |
10528 KB |
Output is correct |
19 |
Correct |
8 ms |
10452 KB |
Output is correct |
20 |
Correct |
7 ms |
10452 KB |
Output is correct |
21 |
Correct |
6 ms |
10452 KB |
Output is correct |
22 |
Correct |
7 ms |
10452 KB |
Output is correct |
23 |
Correct |
7 ms |
10532 KB |
Output is correct |
24 |
Correct |
7 ms |
10452 KB |
Output is correct |
25 |
Correct |
6 ms |
10516 KB |
Output is correct |
26 |
Correct |
7 ms |
10452 KB |
Output is correct |
27 |
Correct |
7 ms |
10452 KB |
Output is correct |
28 |
Correct |
7 ms |
10452 KB |
Output is correct |
29 |
Correct |
60 ms |
10588 KB |
Output is correct |
30 |
Correct |
54 ms |
10640 KB |
Output is correct |
31 |
Correct |
45 ms |
10548 KB |
Output is correct |
32 |
Correct |
34 ms |
10640 KB |
Output is correct |
33 |
Correct |
30 ms |
10580 KB |
Output is correct |
34 |
Correct |
46 ms |
10648 KB |
Output is correct |
35 |
Correct |
56 ms |
10624 KB |
Output is correct |
36 |
Correct |
41 ms |
10640 KB |
Output is correct |
37 |
Correct |
76 ms |
10580 KB |
Output is correct |
38 |
Correct |
74 ms |
10648 KB |
Output is correct |
39 |
Correct |
56 ms |
10628 KB |
Output is correct |
40 |
Correct |
40 ms |
10636 KB |
Output is correct |
41 |
Correct |
39 ms |
10632 KB |
Output is correct |
42 |
Correct |
40 ms |
10580 KB |
Output is correct |
43 |
Correct |
33 ms |
10632 KB |
Output is correct |
44 |
Correct |
34 ms |
10580 KB |
Output is correct |
45 |
Correct |
37 ms |
10580 KB |
Output is correct |
46 |
Correct |
42 ms |
10656 KB |
Output is correct |
47 |
Correct |
44 ms |
10632 KB |
Output is correct |
48 |
Correct |
42 ms |
10580 KB |
Output is correct |
49 |
Correct |
46 ms |
10580 KB |
Output is correct |
50 |
Correct |
52 ms |
10632 KB |
Output is correct |
51 |
Correct |
36 ms |
10580 KB |
Output is correct |
52 |
Correct |
38 ms |
10580 KB |
Output is correct |
53 |
Correct |
44 ms |
10640 KB |
Output is correct |
54 |
Correct |
55 ms |
10648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
10452 KB |
Output is correct |
2 |
Correct |
4 ms |
10452 KB |
Output is correct |
3 |
Correct |
121 ms |
21304 KB |
Output is correct |
4 |
Correct |
282 ms |
22796 KB |
Output is correct |
5 |
Correct |
106 ms |
16432 KB |
Output is correct |
6 |
Correct |
136 ms |
19088 KB |
Output is correct |
7 |
Correct |
122 ms |
18368 KB |
Output is correct |
8 |
Correct |
120 ms |
20160 KB |
Output is correct |
9 |
Correct |
134 ms |
20624 KB |
Output is correct |
10 |
Correct |
172 ms |
20756 KB |
Output is correct |
11 |
Correct |
142 ms |
18256 KB |
Output is correct |
12 |
Correct |
180 ms |
19088 KB |
Output is correct |
13 |
Correct |
100 ms |
17600 KB |
Output is correct |
14 |
Correct |
135 ms |
18932 KB |
Output is correct |
15 |
Correct |
155 ms |
19196 KB |
Output is correct |
16 |
Correct |
187 ms |
19520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
10452 KB |
Output is correct |
2 |
Correct |
4 ms |
10452 KB |
Output is correct |
3 |
Correct |
4 ms |
10452 KB |
Output is correct |
4 |
Correct |
4 ms |
10452 KB |
Output is correct |
5 |
Correct |
4 ms |
10452 KB |
Output is correct |
6 |
Correct |
4 ms |
10452 KB |
Output is correct |
7 |
Correct |
6 ms |
10452 KB |
Output is correct |
8 |
Correct |
7 ms |
10536 KB |
Output is correct |
9 |
Correct |
8 ms |
10432 KB |
Output is correct |
10 |
Correct |
7 ms |
10452 KB |
Output is correct |
11 |
Correct |
9 ms |
10580 KB |
Output is correct |
12 |
Correct |
7 ms |
10452 KB |
Output is correct |
13 |
Correct |
6 ms |
10452 KB |
Output is correct |
14 |
Correct |
7 ms |
10452 KB |
Output is correct |
15 |
Correct |
7 ms |
10452 KB |
Output is correct |
16 |
Correct |
7 ms |
10452 KB |
Output is correct |
17 |
Correct |
7 ms |
10468 KB |
Output is correct |
18 |
Correct |
7 ms |
10528 KB |
Output is correct |
19 |
Correct |
8 ms |
10452 KB |
Output is correct |
20 |
Correct |
7 ms |
10452 KB |
Output is correct |
21 |
Correct |
6 ms |
10452 KB |
Output is correct |
22 |
Correct |
7 ms |
10452 KB |
Output is correct |
23 |
Correct |
7 ms |
10532 KB |
Output is correct |
24 |
Correct |
7 ms |
10452 KB |
Output is correct |
25 |
Correct |
6 ms |
10516 KB |
Output is correct |
26 |
Correct |
7 ms |
10452 KB |
Output is correct |
27 |
Correct |
7 ms |
10452 KB |
Output is correct |
28 |
Correct |
7 ms |
10452 KB |
Output is correct |
29 |
Correct |
121 ms |
21304 KB |
Output is correct |
30 |
Correct |
282 ms |
22796 KB |
Output is correct |
31 |
Correct |
106 ms |
16432 KB |
Output is correct |
32 |
Correct |
136 ms |
19088 KB |
Output is correct |
33 |
Correct |
122 ms |
18368 KB |
Output is correct |
34 |
Correct |
120 ms |
20160 KB |
Output is correct |
35 |
Correct |
134 ms |
20624 KB |
Output is correct |
36 |
Correct |
172 ms |
20756 KB |
Output is correct |
37 |
Correct |
142 ms |
18256 KB |
Output is correct |
38 |
Correct |
180 ms |
19088 KB |
Output is correct |
39 |
Correct |
100 ms |
17600 KB |
Output is correct |
40 |
Correct |
135 ms |
18932 KB |
Output is correct |
41 |
Correct |
155 ms |
19196 KB |
Output is correct |
42 |
Correct |
187 ms |
19520 KB |
Output is correct |
43 |
Execution timed out |
2059 ms |
22476 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
10452 KB |
Output is correct |
2 |
Correct |
4 ms |
10452 KB |
Output is correct |
3 |
Correct |
4 ms |
10452 KB |
Output is correct |
4 |
Correct |
4 ms |
10452 KB |
Output is correct |
5 |
Correct |
4 ms |
10452 KB |
Output is correct |
6 |
Correct |
4 ms |
10452 KB |
Output is correct |
7 |
Correct |
6 ms |
10452 KB |
Output is correct |
8 |
Correct |
7 ms |
10536 KB |
Output is correct |
9 |
Correct |
8 ms |
10432 KB |
Output is correct |
10 |
Correct |
7 ms |
10452 KB |
Output is correct |
11 |
Correct |
9 ms |
10580 KB |
Output is correct |
12 |
Correct |
7 ms |
10452 KB |
Output is correct |
13 |
Correct |
6 ms |
10452 KB |
Output is correct |
14 |
Correct |
7 ms |
10452 KB |
Output is correct |
15 |
Correct |
7 ms |
10452 KB |
Output is correct |
16 |
Correct |
7 ms |
10452 KB |
Output is correct |
17 |
Correct |
7 ms |
10468 KB |
Output is correct |
18 |
Correct |
7 ms |
10528 KB |
Output is correct |
19 |
Correct |
8 ms |
10452 KB |
Output is correct |
20 |
Correct |
7 ms |
10452 KB |
Output is correct |
21 |
Correct |
6 ms |
10452 KB |
Output is correct |
22 |
Correct |
7 ms |
10452 KB |
Output is correct |
23 |
Correct |
7 ms |
10532 KB |
Output is correct |
24 |
Correct |
7 ms |
10452 KB |
Output is correct |
25 |
Correct |
6 ms |
10516 KB |
Output is correct |
26 |
Correct |
7 ms |
10452 KB |
Output is correct |
27 |
Correct |
7 ms |
10452 KB |
Output is correct |
28 |
Correct |
7 ms |
10452 KB |
Output is correct |
29 |
Correct |
60 ms |
10588 KB |
Output is correct |
30 |
Correct |
54 ms |
10640 KB |
Output is correct |
31 |
Correct |
45 ms |
10548 KB |
Output is correct |
32 |
Correct |
34 ms |
10640 KB |
Output is correct |
33 |
Correct |
30 ms |
10580 KB |
Output is correct |
34 |
Correct |
46 ms |
10648 KB |
Output is correct |
35 |
Correct |
56 ms |
10624 KB |
Output is correct |
36 |
Correct |
41 ms |
10640 KB |
Output is correct |
37 |
Correct |
76 ms |
10580 KB |
Output is correct |
38 |
Correct |
74 ms |
10648 KB |
Output is correct |
39 |
Correct |
56 ms |
10628 KB |
Output is correct |
40 |
Correct |
40 ms |
10636 KB |
Output is correct |
41 |
Correct |
39 ms |
10632 KB |
Output is correct |
42 |
Correct |
40 ms |
10580 KB |
Output is correct |
43 |
Correct |
33 ms |
10632 KB |
Output is correct |
44 |
Correct |
34 ms |
10580 KB |
Output is correct |
45 |
Correct |
37 ms |
10580 KB |
Output is correct |
46 |
Correct |
42 ms |
10656 KB |
Output is correct |
47 |
Correct |
44 ms |
10632 KB |
Output is correct |
48 |
Correct |
42 ms |
10580 KB |
Output is correct |
49 |
Correct |
46 ms |
10580 KB |
Output is correct |
50 |
Correct |
52 ms |
10632 KB |
Output is correct |
51 |
Correct |
36 ms |
10580 KB |
Output is correct |
52 |
Correct |
38 ms |
10580 KB |
Output is correct |
53 |
Correct |
44 ms |
10640 KB |
Output is correct |
54 |
Correct |
55 ms |
10648 KB |
Output is correct |
55 |
Execution timed out |
2057 ms |
18260 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
10452 KB |
Output is correct |
2 |
Correct |
4 ms |
10452 KB |
Output is correct |
3 |
Correct |
4 ms |
10452 KB |
Output is correct |
4 |
Correct |
4 ms |
10452 KB |
Output is correct |
5 |
Correct |
4 ms |
10452 KB |
Output is correct |
6 |
Correct |
4 ms |
10452 KB |
Output is correct |
7 |
Correct |
6 ms |
10452 KB |
Output is correct |
8 |
Correct |
7 ms |
10536 KB |
Output is correct |
9 |
Correct |
8 ms |
10432 KB |
Output is correct |
10 |
Correct |
7 ms |
10452 KB |
Output is correct |
11 |
Correct |
9 ms |
10580 KB |
Output is correct |
12 |
Correct |
7 ms |
10452 KB |
Output is correct |
13 |
Correct |
6 ms |
10452 KB |
Output is correct |
14 |
Correct |
7 ms |
10452 KB |
Output is correct |
15 |
Correct |
7 ms |
10452 KB |
Output is correct |
16 |
Correct |
7 ms |
10452 KB |
Output is correct |
17 |
Correct |
7 ms |
10468 KB |
Output is correct |
18 |
Correct |
7 ms |
10528 KB |
Output is correct |
19 |
Correct |
8 ms |
10452 KB |
Output is correct |
20 |
Correct |
7 ms |
10452 KB |
Output is correct |
21 |
Correct |
6 ms |
10452 KB |
Output is correct |
22 |
Correct |
7 ms |
10452 KB |
Output is correct |
23 |
Correct |
7 ms |
10532 KB |
Output is correct |
24 |
Correct |
7 ms |
10452 KB |
Output is correct |
25 |
Correct |
6 ms |
10516 KB |
Output is correct |
26 |
Correct |
7 ms |
10452 KB |
Output is correct |
27 |
Correct |
7 ms |
10452 KB |
Output is correct |
28 |
Correct |
7 ms |
10452 KB |
Output is correct |
29 |
Correct |
60 ms |
10588 KB |
Output is correct |
30 |
Correct |
54 ms |
10640 KB |
Output is correct |
31 |
Correct |
45 ms |
10548 KB |
Output is correct |
32 |
Correct |
34 ms |
10640 KB |
Output is correct |
33 |
Correct |
30 ms |
10580 KB |
Output is correct |
34 |
Correct |
46 ms |
10648 KB |
Output is correct |
35 |
Correct |
56 ms |
10624 KB |
Output is correct |
36 |
Correct |
41 ms |
10640 KB |
Output is correct |
37 |
Correct |
76 ms |
10580 KB |
Output is correct |
38 |
Correct |
74 ms |
10648 KB |
Output is correct |
39 |
Correct |
56 ms |
10628 KB |
Output is correct |
40 |
Correct |
40 ms |
10636 KB |
Output is correct |
41 |
Correct |
39 ms |
10632 KB |
Output is correct |
42 |
Correct |
40 ms |
10580 KB |
Output is correct |
43 |
Correct |
33 ms |
10632 KB |
Output is correct |
44 |
Correct |
34 ms |
10580 KB |
Output is correct |
45 |
Correct |
37 ms |
10580 KB |
Output is correct |
46 |
Correct |
42 ms |
10656 KB |
Output is correct |
47 |
Correct |
44 ms |
10632 KB |
Output is correct |
48 |
Correct |
42 ms |
10580 KB |
Output is correct |
49 |
Correct |
46 ms |
10580 KB |
Output is correct |
50 |
Correct |
52 ms |
10632 KB |
Output is correct |
51 |
Correct |
36 ms |
10580 KB |
Output is correct |
52 |
Correct |
38 ms |
10580 KB |
Output is correct |
53 |
Correct |
44 ms |
10640 KB |
Output is correct |
54 |
Correct |
55 ms |
10648 KB |
Output is correct |
55 |
Correct |
121 ms |
21304 KB |
Output is correct |
56 |
Correct |
282 ms |
22796 KB |
Output is correct |
57 |
Correct |
106 ms |
16432 KB |
Output is correct |
58 |
Correct |
136 ms |
19088 KB |
Output is correct |
59 |
Correct |
122 ms |
18368 KB |
Output is correct |
60 |
Correct |
120 ms |
20160 KB |
Output is correct |
61 |
Correct |
134 ms |
20624 KB |
Output is correct |
62 |
Correct |
172 ms |
20756 KB |
Output is correct |
63 |
Correct |
142 ms |
18256 KB |
Output is correct |
64 |
Correct |
180 ms |
19088 KB |
Output is correct |
65 |
Correct |
100 ms |
17600 KB |
Output is correct |
66 |
Correct |
135 ms |
18932 KB |
Output is correct |
67 |
Correct |
155 ms |
19196 KB |
Output is correct |
68 |
Correct |
187 ms |
19520 KB |
Output is correct |
69 |
Execution timed out |
2059 ms |
22476 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |