#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rng(i,l,r) for(int i=(l); i<(r); i++)
#define all(x) x.begin(),x.end()
using ll=long long;
struct odd_cycle {
int size;
vector<int> uni;
int time;
stack<array<int,4>> memo;
bool isok;
odd_cycle(int sz) {
size=sz;
time=0;
isok=false;
memo.push({-1,-1,0,-1});
uni.resize(size*2,-1);
}
int leader(int p) {
while(uni[p]>=0)p=uni[p];
return p;
}
void merge(pair<int,int> x) {
if(isok) {
time++;
return;
}
int u=x.first;
int v=x.second;
int a=leader(u),d=leader(v+size);
if(-uni[a]>-uni[d])swap(a,d);
if(a!=d) {
memo.push({a,uni[a],isok,time});
memo.push({d,uni[d],isok,time});
uni[d]+=uni[a];
uni[a]=d;
}
int b=leader(v),c=leader(u+size);
if(-uni[b]>-uni[c])swap(b,c);
if(b!=c) {
memo.push({b,uni[b],isok,time});
memo.push({c,uni[c],isok,time});
uni[c]+=uni[b];
uni[b]=c;
}
if(leader(u)==leader(u+size))isok=true;
time++;
}
void undo() {
time--;
while(memo.top()[3]==time) {
isok=memo.top()[2];
uni[memo.top()[0]]=memo.top()[1];
memo.pop();
}
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M,Q;
cin>>N>>M>>Q;
const int backet=316;
vector<pair<int,int>> edge(M);
rep(i,M) {
int u,v;
cin>>u>>v;
edge[i]={u-1,v-1};
}
vector<vector<array<int,3>>> query(3+M/backet);
rep(i,Q) {
int l,r;
cin>>l>>r;
query[(l-1)/backet].push_back({-r,l-1,i});
}
vector<string> ans(Q);
rep(i,3+M/backet) {
if(query[i].empty())continue;
sort(all(query[i]));
odd_cycle uni(N);
rep(j,backet*i)uni.merge(edge[j]);
int ri=M;
rep(j,query[i].size()) {
int r=-query[i][j][0];
int l=query[i][j][1];
int ind=query[i][j][2];
rng(k,r,ri) {
uni.merge(edge[k]);
}
ri=r;
rep(k,l%backet) {
uni.merge(edge[i*backet+k]);
}
if(uni.isok)ans[ind]="YES";
else ans[ind]="NO";
rep(k,l%backet) {
uni.undo();
}
}
}
rep(i,Q) {
cout<<ans[i]<<"\n";
}
}
Compilation message
Joker.cpp: In function 'int main()':
Joker.cpp:3:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define rep(i,n) for(int i=0; i<(n); i++)
| ^
Joker.cpp:86:9: note: in expansion of macro 'rep'
86 | rep(j,query[i].size()) {
| ^~~
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 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 |
348 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 |
344 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 |
448 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 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 |
348 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 |
344 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 |
448 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
13 ms |
604 KB |
Output is correct |
30 |
Correct |
9 ms |
708 KB |
Output is correct |
31 |
Correct |
6 ms |
600 KB |
Output is correct |
32 |
Correct |
5 ms |
604 KB |
Output is correct |
33 |
Correct |
4 ms |
736 KB |
Output is correct |
34 |
Correct |
6 ms |
708 KB |
Output is correct |
35 |
Correct |
11 ms |
604 KB |
Output is correct |
36 |
Correct |
9 ms |
604 KB |
Output is correct |
37 |
Correct |
11 ms |
756 KB |
Output is correct |
38 |
Correct |
14 ms |
604 KB |
Output is correct |
39 |
Correct |
10 ms |
732 KB |
Output is correct |
40 |
Correct |
6 ms |
600 KB |
Output is correct |
41 |
Correct |
8 ms |
696 KB |
Output is correct |
42 |
Correct |
7 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
464 KB |
Output is correct |
44 |
Correct |
2 ms |
684 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
3 ms |
728 KB |
Output is correct |
47 |
Correct |
6 ms |
604 KB |
Output is correct |
48 |
Correct |
6 ms |
516 KB |
Output is correct |
49 |
Correct |
7 ms |
604 KB |
Output is correct |
50 |
Correct |
8 ms |
728 KB |
Output is correct |
51 |
Correct |
5 ms |
668 KB |
Output is correct |
52 |
Correct |
6 ms |
604 KB |
Output is correct |
53 |
Correct |
10 ms |
684 KB |
Output is correct |
54 |
Correct |
8 ms |
708 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 |
75 ms |
20752 KB |
Output is correct |
4 |
Correct |
78 ms |
27376 KB |
Output is correct |
5 |
Correct |
72 ms |
16316 KB |
Output is correct |
6 |
Correct |
84 ms |
20160 KB |
Output is correct |
7 |
Correct |
75 ms |
20240 KB |
Output is correct |
8 |
Correct |
71 ms |
16532 KB |
Output is correct |
9 |
Correct |
86 ms |
19460 KB |
Output is correct |
10 |
Correct |
75 ms |
21188 KB |
Output is correct |
11 |
Correct |
86 ms |
19136 KB |
Output is correct |
12 |
Correct |
89 ms |
20796 KB |
Output is correct |
13 |
Correct |
81 ms |
15040 KB |
Output is correct |
14 |
Correct |
115 ms |
17132 KB |
Output is correct |
15 |
Correct |
70 ms |
20932 KB |
Output is correct |
16 |
Correct |
70 ms |
21016 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 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 |
348 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 |
344 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 |
448 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
75 ms |
20752 KB |
Output is correct |
30 |
Correct |
78 ms |
27376 KB |
Output is correct |
31 |
Correct |
72 ms |
16316 KB |
Output is correct |
32 |
Correct |
84 ms |
20160 KB |
Output is correct |
33 |
Correct |
75 ms |
20240 KB |
Output is correct |
34 |
Correct |
71 ms |
16532 KB |
Output is correct |
35 |
Correct |
86 ms |
19460 KB |
Output is correct |
36 |
Correct |
75 ms |
21188 KB |
Output is correct |
37 |
Correct |
86 ms |
19136 KB |
Output is correct |
38 |
Correct |
89 ms |
20796 KB |
Output is correct |
39 |
Correct |
81 ms |
15040 KB |
Output is correct |
40 |
Correct |
115 ms |
17132 KB |
Output is correct |
41 |
Correct |
70 ms |
20932 KB |
Output is correct |
42 |
Correct |
70 ms |
21016 KB |
Output is correct |
43 |
Correct |
753 ms |
22248 KB |
Output is correct |
44 |
Correct |
863 ms |
29260 KB |
Output is correct |
45 |
Correct |
863 ms |
28872 KB |
Output is correct |
46 |
Correct |
654 ms |
22604 KB |
Output is correct |
47 |
Correct |
672 ms |
22960 KB |
Output is correct |
48 |
Correct |
243 ms |
20668 KB |
Output is correct |
49 |
Correct |
306 ms |
22920 KB |
Output is correct |
50 |
Correct |
442 ms |
21436 KB |
Output is correct |
51 |
Correct |
625 ms |
22984 KB |
Output is correct |
52 |
Correct |
722 ms |
23360 KB |
Output is correct |
53 |
Correct |
282 ms |
16868 KB |
Output is correct |
54 |
Correct |
752 ms |
20128 KB |
Output is correct |
55 |
Correct |
755 ms |
23064 KB |
Output is correct |
56 |
Correct |
826 ms |
23580 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 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 |
348 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 |
344 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 |
448 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
13 ms |
604 KB |
Output is correct |
30 |
Correct |
9 ms |
708 KB |
Output is correct |
31 |
Correct |
6 ms |
600 KB |
Output is correct |
32 |
Correct |
5 ms |
604 KB |
Output is correct |
33 |
Correct |
4 ms |
736 KB |
Output is correct |
34 |
Correct |
6 ms |
708 KB |
Output is correct |
35 |
Correct |
11 ms |
604 KB |
Output is correct |
36 |
Correct |
9 ms |
604 KB |
Output is correct |
37 |
Correct |
11 ms |
756 KB |
Output is correct |
38 |
Correct |
14 ms |
604 KB |
Output is correct |
39 |
Correct |
10 ms |
732 KB |
Output is correct |
40 |
Correct |
6 ms |
600 KB |
Output is correct |
41 |
Correct |
8 ms |
696 KB |
Output is correct |
42 |
Correct |
7 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
464 KB |
Output is correct |
44 |
Correct |
2 ms |
684 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
3 ms |
728 KB |
Output is correct |
47 |
Correct |
6 ms |
604 KB |
Output is correct |
48 |
Correct |
6 ms |
516 KB |
Output is correct |
49 |
Correct |
7 ms |
604 KB |
Output is correct |
50 |
Correct |
8 ms |
728 KB |
Output is correct |
51 |
Correct |
5 ms |
668 KB |
Output is correct |
52 |
Correct |
6 ms |
604 KB |
Output is correct |
53 |
Correct |
10 ms |
684 KB |
Output is correct |
54 |
Correct |
8 ms |
708 KB |
Output is correct |
55 |
Execution timed out |
2033 ms |
11876 KB |
Time limit exceeded |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
600 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 |
348 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 |
344 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 |
448 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
13 ms |
604 KB |
Output is correct |
30 |
Correct |
9 ms |
708 KB |
Output is correct |
31 |
Correct |
6 ms |
600 KB |
Output is correct |
32 |
Correct |
5 ms |
604 KB |
Output is correct |
33 |
Correct |
4 ms |
736 KB |
Output is correct |
34 |
Correct |
6 ms |
708 KB |
Output is correct |
35 |
Correct |
11 ms |
604 KB |
Output is correct |
36 |
Correct |
9 ms |
604 KB |
Output is correct |
37 |
Correct |
11 ms |
756 KB |
Output is correct |
38 |
Correct |
14 ms |
604 KB |
Output is correct |
39 |
Correct |
10 ms |
732 KB |
Output is correct |
40 |
Correct |
6 ms |
600 KB |
Output is correct |
41 |
Correct |
8 ms |
696 KB |
Output is correct |
42 |
Correct |
7 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
464 KB |
Output is correct |
44 |
Correct |
2 ms |
684 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
3 ms |
728 KB |
Output is correct |
47 |
Correct |
6 ms |
604 KB |
Output is correct |
48 |
Correct |
6 ms |
516 KB |
Output is correct |
49 |
Correct |
7 ms |
604 KB |
Output is correct |
50 |
Correct |
8 ms |
728 KB |
Output is correct |
51 |
Correct |
5 ms |
668 KB |
Output is correct |
52 |
Correct |
6 ms |
604 KB |
Output is correct |
53 |
Correct |
10 ms |
684 KB |
Output is correct |
54 |
Correct |
8 ms |
708 KB |
Output is correct |
55 |
Correct |
75 ms |
20752 KB |
Output is correct |
56 |
Correct |
78 ms |
27376 KB |
Output is correct |
57 |
Correct |
72 ms |
16316 KB |
Output is correct |
58 |
Correct |
84 ms |
20160 KB |
Output is correct |
59 |
Correct |
75 ms |
20240 KB |
Output is correct |
60 |
Correct |
71 ms |
16532 KB |
Output is correct |
61 |
Correct |
86 ms |
19460 KB |
Output is correct |
62 |
Correct |
75 ms |
21188 KB |
Output is correct |
63 |
Correct |
86 ms |
19136 KB |
Output is correct |
64 |
Correct |
89 ms |
20796 KB |
Output is correct |
65 |
Correct |
81 ms |
15040 KB |
Output is correct |
66 |
Correct |
115 ms |
17132 KB |
Output is correct |
67 |
Correct |
70 ms |
20932 KB |
Output is correct |
68 |
Correct |
70 ms |
21016 KB |
Output is correct |
69 |
Correct |
753 ms |
22248 KB |
Output is correct |
70 |
Correct |
863 ms |
29260 KB |
Output is correct |
71 |
Correct |
863 ms |
28872 KB |
Output is correct |
72 |
Correct |
654 ms |
22604 KB |
Output is correct |
73 |
Correct |
672 ms |
22960 KB |
Output is correct |
74 |
Correct |
243 ms |
20668 KB |
Output is correct |
75 |
Correct |
306 ms |
22920 KB |
Output is correct |
76 |
Correct |
442 ms |
21436 KB |
Output is correct |
77 |
Correct |
625 ms |
22984 KB |
Output is correct |
78 |
Correct |
722 ms |
23360 KB |
Output is correct |
79 |
Correct |
282 ms |
16868 KB |
Output is correct |
80 |
Correct |
752 ms |
20128 KB |
Output is correct |
81 |
Correct |
755 ms |
23064 KB |
Output is correct |
82 |
Correct |
826 ms |
23580 KB |
Output is correct |
83 |
Execution timed out |
2033 ms |
11876 KB |
Time limit exceeded |
84 |
Halted |
0 ms |
0 KB |
- |