#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int MAX = 200010;
struct edge_t { int u, v; };
struct stat_t { int x, p, s, b; };
inline int _min(int a, int b){ return a<b ? a : b; }
inline int _max(int a, int b){ return a>b ? a : b; }
class bipuf {
bool bip;
int n, U[MAX*2], S[MAX*2];
vector<stat_t> hist;
int find(int x){
return x==U[x] ? x : find(U[x]);
}
stat_t unite(int u, int v){
u = find(u), v = find(v);
stat_t bef = {0, 0, 0, bip};
if(u==v) return bef;
if(S[u]>S[v]) swap(u, v);
bef = {u, U[u], S[v], bip};
U[u] = v; S[v] += S[u];
return bef;
}
void revert(stat_t st){
bip = st.b;
int v = st.x;
if(v==0) return;
S[U[v]] = st.s;
U[v] = st.p;
}
public:
bipuf(int sz){
bip = true;
n = 2*sz+1;
iota(U+1, U+n+1, 1);
fill(S+1, S+n+1, 1);
}
void add_edge(edge_t e){
int u = e.u, v = e.v;
stat_t st1 = unite(u*2, v*2+1);
stat_t st2 = unite(u*2+1, v*2);
if(find(u*2) == find(u*2+1) || find(v*2) == find(v*2+1))
bip = false;
hist.push_back(st1);
hist.push_back(st2);
}
void pop_edge(){
stat_t st2 = hist.back(); hist.pop_back();
stat_t st1 = hist.back(); hist.pop_back();
revert(st2); revert(st1);
}
bool is_bip(){
return bip;
}
};
int n, m, q;
edge_t E[MAX];
int pos[MAX];
// pos[l] : using ([1,l] + [pos[l], m]) is bipartite
void solve(int s, int e, int l, int r, bipuf &UF){
// UF set as [1, s) + (r, m]
if(e>s) return;
int mid = (s+e)/2, &p = pos[mid];
for(int i=_max(1, s); i<=mid; i++)
UF.add_edge(E[i]);
// [1, mid] + (r, m]
int bgn = _min(r, m), fin = _max(l, mid+1);
for(int i=bgn; i>=fin; i--){
UF.add_edge(E[i]);
if(UF.is_bip()) p=i;
}
int sto = _min(bgn, p);
// [1, mid] + [fin, m]
for(int i=fin; i<=sto; i++)
UF.pop_edge();
// [1, mid] + (sto, m]
solve(s, mid-1, l, p, UF);
// set UF
solve(mid+1, e, p, r, UF);
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>m>>q;
for(int i=1; i<=m; i++){
int u, v; cin>>u>>v;
E[i] = {u, v};
}
fill(pos, pos+m+1, m+2);
static bipuf UF(n);
// solve(0, m, 1, m+1, UF);
for(int i=1; i<=q; i++){
int l, r; cin>>l>>r;
for(int j=1; j<l; j++)
UF.add_edge(E[j]);
for(int j=m; j>r; j--)
UF.add_edge(E[j]);
cout<<(UF.is_bip() ? "NO" : "YES")<<'\n';
for(int j=1; j<l; j++)
UF.pop_edge();
for(int j=m; j>r; j--)
UF.pop_edge();
// cout<<(pos[l-1] <= r+1 ? "NO" : "YES")<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
436 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
436 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
73 ms |
544 KB |
Output is correct |
30 |
Correct |
95 ms |
632 KB |
Output is correct |
31 |
Correct |
116 ms |
624 KB |
Output is correct |
32 |
Correct |
107 ms |
512 KB |
Output is correct |
33 |
Correct |
114 ms |
512 KB |
Output is correct |
34 |
Correct |
108 ms |
636 KB |
Output is correct |
35 |
Correct |
117 ms |
632 KB |
Output is correct |
36 |
Correct |
71 ms |
632 KB |
Output is correct |
37 |
Correct |
113 ms |
632 KB |
Output is correct |
38 |
Correct |
132 ms |
632 KB |
Output is correct |
39 |
Correct |
82 ms |
640 KB |
Output is correct |
40 |
Correct |
98 ms |
632 KB |
Output is correct |
41 |
Correct |
95 ms |
632 KB |
Output is correct |
42 |
Correct |
94 ms |
632 KB |
Output is correct |
43 |
Correct |
200 ms |
632 KB |
Output is correct |
44 |
Correct |
199 ms |
632 KB |
Output is correct |
45 |
Correct |
194 ms |
636 KB |
Output is correct |
46 |
Correct |
178 ms |
632 KB |
Output is correct |
47 |
Correct |
94 ms |
632 KB |
Output is correct |
48 |
Correct |
97 ms |
632 KB |
Output is correct |
49 |
Correct |
100 ms |
632 KB |
Output is correct |
50 |
Correct |
104 ms |
636 KB |
Output is correct |
51 |
Correct |
118 ms |
632 KB |
Output is correct |
52 |
Correct |
116 ms |
632 KB |
Output is correct |
53 |
Correct |
112 ms |
632 KB |
Output is correct |
54 |
Correct |
117 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Execution timed out |
2072 ms |
12904 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
436 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Execution timed out |
2072 ms |
12904 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
436 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
73 ms |
544 KB |
Output is correct |
30 |
Correct |
95 ms |
632 KB |
Output is correct |
31 |
Correct |
116 ms |
624 KB |
Output is correct |
32 |
Correct |
107 ms |
512 KB |
Output is correct |
33 |
Correct |
114 ms |
512 KB |
Output is correct |
34 |
Correct |
108 ms |
636 KB |
Output is correct |
35 |
Correct |
117 ms |
632 KB |
Output is correct |
36 |
Correct |
71 ms |
632 KB |
Output is correct |
37 |
Correct |
113 ms |
632 KB |
Output is correct |
38 |
Correct |
132 ms |
632 KB |
Output is correct |
39 |
Correct |
82 ms |
640 KB |
Output is correct |
40 |
Correct |
98 ms |
632 KB |
Output is correct |
41 |
Correct |
95 ms |
632 KB |
Output is correct |
42 |
Correct |
94 ms |
632 KB |
Output is correct |
43 |
Correct |
200 ms |
632 KB |
Output is correct |
44 |
Correct |
199 ms |
632 KB |
Output is correct |
45 |
Correct |
194 ms |
636 KB |
Output is correct |
46 |
Correct |
178 ms |
632 KB |
Output is correct |
47 |
Correct |
94 ms |
632 KB |
Output is correct |
48 |
Correct |
97 ms |
632 KB |
Output is correct |
49 |
Correct |
100 ms |
632 KB |
Output is correct |
50 |
Correct |
104 ms |
636 KB |
Output is correct |
51 |
Correct |
118 ms |
632 KB |
Output is correct |
52 |
Correct |
116 ms |
632 KB |
Output is correct |
53 |
Correct |
112 ms |
632 KB |
Output is correct |
54 |
Correct |
117 ms |
632 KB |
Output is correct |
55 |
Execution timed out |
2076 ms |
12612 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
436 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
73 ms |
544 KB |
Output is correct |
30 |
Correct |
95 ms |
632 KB |
Output is correct |
31 |
Correct |
116 ms |
624 KB |
Output is correct |
32 |
Correct |
107 ms |
512 KB |
Output is correct |
33 |
Correct |
114 ms |
512 KB |
Output is correct |
34 |
Correct |
108 ms |
636 KB |
Output is correct |
35 |
Correct |
117 ms |
632 KB |
Output is correct |
36 |
Correct |
71 ms |
632 KB |
Output is correct |
37 |
Correct |
113 ms |
632 KB |
Output is correct |
38 |
Correct |
132 ms |
632 KB |
Output is correct |
39 |
Correct |
82 ms |
640 KB |
Output is correct |
40 |
Correct |
98 ms |
632 KB |
Output is correct |
41 |
Correct |
95 ms |
632 KB |
Output is correct |
42 |
Correct |
94 ms |
632 KB |
Output is correct |
43 |
Correct |
200 ms |
632 KB |
Output is correct |
44 |
Correct |
199 ms |
632 KB |
Output is correct |
45 |
Correct |
194 ms |
636 KB |
Output is correct |
46 |
Correct |
178 ms |
632 KB |
Output is correct |
47 |
Correct |
94 ms |
632 KB |
Output is correct |
48 |
Correct |
97 ms |
632 KB |
Output is correct |
49 |
Correct |
100 ms |
632 KB |
Output is correct |
50 |
Correct |
104 ms |
636 KB |
Output is correct |
51 |
Correct |
118 ms |
632 KB |
Output is correct |
52 |
Correct |
116 ms |
632 KB |
Output is correct |
53 |
Correct |
112 ms |
632 KB |
Output is correct |
54 |
Correct |
117 ms |
632 KB |
Output is correct |
55 |
Execution timed out |
2072 ms |
12904 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |