#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int , int> pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 2e5+10;
const ll mod = 1e9+7;
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
int n, m, q;
int a[maxn], b[maxn], l[maxn], r[maxn];
int par[maxn], sz[maxn];
bool val[maxn];
int getpar(int v){
return ((~par[v]) ? getpar(par[v]) : v);
}
bool getval(int v){
return ((~par[v]) ? val[v] ^ getval(par[v]) : val[v]);
}
bool merge(int v, int u){
int pu = getpar(u) , pv = getpar(v);
if(pu == pv)
return getval(u) == getval(v);
if(sz[pu] > sz[pv])swap(pu , pv);
val[pu] ^= getval(v) == getval(u);
par[pu] = pv;
sz[pv] += sz[pu];
return 0;
}
bool solve(int l , int r){
for(int i = 0 ; i < l ; i ++){
if(merge(a[i], b[i])){
if(i > n){
for(int j = 0 ; j < n ; j ++)
par[j] = -1, val[j] = 0, sz[j] = 1;
}
else{
for(int j = 0; j <= i ; j ++)
par[a[j]] = par[b[j]] = -1 , val[a[j]] = val[b[j]] = 0 , sz[a[j]] = sz[b[j]] = 1;
}
return 1;
}
}
for(int i = r ; i < m ; i ++){
if(merge(a[i], b[i])){
if(l + i - r > n){
for(int j = 0 ; j < n ; j ++)
par[j] = -1, val[j] = 0 , sz[j] = 1;
}
else{
for(int j = 0; j < l ; j ++)
par[a[j]] = par[b[j]] = -1 , val[a[j]] = val[b[j]] = 0 , sz[a[j]] = sz[b[j]] = 1;
for(int j = r ; j <= i ; j ++)
par[a[j]] = par[b[j]] = -1 , val[a[j]] = val[b[j]] = 0 , sz[a[j]] = sz[b[j]] = 1;
}
return 1;
}
}
if(m - r - l < n){
for(int j = 0; j < l ; j ++)
par[a[j]] = par[b[j]] = -1 , val[a[j]] = val[b[j]] = 0 , sz[a[j]] = sz[b[j]] = 1;
for(int j = r ; j < m ; j ++)
par[a[j]] = par[b[j]] = -1 , val[a[j]] = val[b[j]] = 0 , sz[a[j]] = sz[b[j]] = 1;
}
else{
for(int j = 0 ; j < n ; j ++)
par[j] = -1, val[j] = 0 , sz[j] = 1;
}
return 0;
}
bool sub3 = 0;
int srt[maxn];
bool ans[maxn];
int32_t main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin >> n >> m >> q;
ms(par, -1);
for(int i = 0 ; i < m ; i ++)
cin >> a[i] >> b[i] , a[i] -- , b[i] --;
for(int i = 0 ; i < n ; i ++)sz[i] = 1;
for(int i = 0 ; i < q ; i ++)
cin >> l[i] >> r[i], l[i] --, sub3 |= l[i];
if(n <= 2000 and m <= 2000 and q <= 2000){
for(int i = 0 ; i < q ; i ++)
cout << (solve(l[i] , r[i]) ? "YES" : "NO") << endl;
return 0;
}
if(!sub3){
for(int i = 0 ; i < q ; i ++)
srt[i] = i;
sort(srt , srt + q , [](int i, int j){return r[i] > r[j];});
bool cur = 0;
int pos = m-1;
for(int i = 0 ; i < q ; i ++){
while(pos >= r[srt[i]]){
cur |= merge(a[pos], b[pos]);
pos --;
}
ans[srt[i]] = cur;
}
for(int i = 0 ; i < q ; i ++)
cout << ((ans[i]) ? "YES" : "NO") << endl;
return 0;
}
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
2 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
2 ms |
1100 KB |
Output is correct |
15 |
Correct |
2 ms |
1100 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
2 ms |
1100 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
2 ms |
1100 KB |
Output is correct |
20 |
Correct |
0 ms |
1100 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
2 ms |
1100 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
2 ms |
1100 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1064 KB |
Output is correct |
27 |
Correct |
1 ms |
1100 KB |
Output is correct |
28 |
Correct |
2 ms |
1100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
2 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
2 ms |
1100 KB |
Output is correct |
15 |
Correct |
2 ms |
1100 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
2 ms |
1100 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
2 ms |
1100 KB |
Output is correct |
20 |
Correct |
0 ms |
1100 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
2 ms |
1100 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
2 ms |
1100 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1064 KB |
Output is correct |
27 |
Correct |
1 ms |
1100 KB |
Output is correct |
28 |
Correct |
2 ms |
1100 KB |
Output is correct |
29 |
Correct |
33 ms |
1100 KB |
Output is correct |
30 |
Correct |
47 ms |
1100 KB |
Output is correct |
31 |
Correct |
42 ms |
1172 KB |
Output is correct |
32 |
Correct |
23 ms |
1100 KB |
Output is correct |
33 |
Correct |
15 ms |
1160 KB |
Output is correct |
34 |
Correct |
25 ms |
1172 KB |
Output is correct |
35 |
Correct |
42 ms |
1100 KB |
Output is correct |
36 |
Correct |
32 ms |
1164 KB |
Output is correct |
37 |
Correct |
63 ms |
1172 KB |
Output is correct |
38 |
Correct |
76 ms |
1176 KB |
Output is correct |
39 |
Correct |
51 ms |
1100 KB |
Output is correct |
40 |
Correct |
41 ms |
1156 KB |
Output is correct |
41 |
Correct |
38 ms |
1100 KB |
Output is correct |
42 |
Correct |
29 ms |
1100 KB |
Output is correct |
43 |
Correct |
44 ms |
1160 KB |
Output is correct |
44 |
Correct |
39 ms |
1164 KB |
Output is correct |
45 |
Correct |
39 ms |
1100 KB |
Output is correct |
46 |
Correct |
39 ms |
1176 KB |
Output is correct |
47 |
Correct |
36 ms |
1228 KB |
Output is correct |
48 |
Correct |
40 ms |
1168 KB |
Output is correct |
49 |
Correct |
46 ms |
1100 KB |
Output is correct |
50 |
Correct |
37 ms |
1180 KB |
Output is correct |
51 |
Correct |
35 ms |
1100 KB |
Output is correct |
52 |
Correct |
33 ms |
1168 KB |
Output is correct |
53 |
Correct |
37 ms |
1168 KB |
Output is correct |
54 |
Correct |
41 ms |
1172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
119 ms |
6292 KB |
Output is correct |
4 |
Correct |
124 ms |
10268 KB |
Output is correct |
5 |
Correct |
118 ms |
10968 KB |
Output is correct |
6 |
Correct |
124 ms |
10248 KB |
Output is correct |
7 |
Correct |
118 ms |
10308 KB |
Output is correct |
8 |
Correct |
116 ms |
9500 KB |
Output is correct |
9 |
Correct |
112 ms |
9796 KB |
Output is correct |
10 |
Correct |
117 ms |
10436 KB |
Output is correct |
11 |
Correct |
119 ms |
10192 KB |
Output is correct |
12 |
Correct |
129 ms |
10764 KB |
Output is correct |
13 |
Correct |
121 ms |
9804 KB |
Output is correct |
14 |
Correct |
135 ms |
10096 KB |
Output is correct |
15 |
Correct |
146 ms |
10468 KB |
Output is correct |
16 |
Correct |
125 ms |
10824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
2 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
2 ms |
1100 KB |
Output is correct |
15 |
Correct |
2 ms |
1100 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
2 ms |
1100 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
2 ms |
1100 KB |
Output is correct |
20 |
Correct |
0 ms |
1100 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
2 ms |
1100 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
2 ms |
1100 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1064 KB |
Output is correct |
27 |
Correct |
1 ms |
1100 KB |
Output is correct |
28 |
Correct |
2 ms |
1100 KB |
Output is correct |
29 |
Correct |
119 ms |
6292 KB |
Output is correct |
30 |
Correct |
124 ms |
10268 KB |
Output is correct |
31 |
Correct |
118 ms |
10968 KB |
Output is correct |
32 |
Correct |
124 ms |
10248 KB |
Output is correct |
33 |
Correct |
118 ms |
10308 KB |
Output is correct |
34 |
Correct |
116 ms |
9500 KB |
Output is correct |
35 |
Correct |
112 ms |
9796 KB |
Output is correct |
36 |
Correct |
117 ms |
10436 KB |
Output is correct |
37 |
Correct |
119 ms |
10192 KB |
Output is correct |
38 |
Correct |
129 ms |
10764 KB |
Output is correct |
39 |
Correct |
121 ms |
9804 KB |
Output is correct |
40 |
Correct |
135 ms |
10096 KB |
Output is correct |
41 |
Correct |
146 ms |
10468 KB |
Output is correct |
42 |
Correct |
125 ms |
10824 KB |
Output is correct |
43 |
Incorrect |
84 ms |
8900 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
2 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
2 ms |
1100 KB |
Output is correct |
15 |
Correct |
2 ms |
1100 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
2 ms |
1100 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
2 ms |
1100 KB |
Output is correct |
20 |
Correct |
0 ms |
1100 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
2 ms |
1100 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
2 ms |
1100 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1064 KB |
Output is correct |
27 |
Correct |
1 ms |
1100 KB |
Output is correct |
28 |
Correct |
2 ms |
1100 KB |
Output is correct |
29 |
Correct |
33 ms |
1100 KB |
Output is correct |
30 |
Correct |
47 ms |
1100 KB |
Output is correct |
31 |
Correct |
42 ms |
1172 KB |
Output is correct |
32 |
Correct |
23 ms |
1100 KB |
Output is correct |
33 |
Correct |
15 ms |
1160 KB |
Output is correct |
34 |
Correct |
25 ms |
1172 KB |
Output is correct |
35 |
Correct |
42 ms |
1100 KB |
Output is correct |
36 |
Correct |
32 ms |
1164 KB |
Output is correct |
37 |
Correct |
63 ms |
1172 KB |
Output is correct |
38 |
Correct |
76 ms |
1176 KB |
Output is correct |
39 |
Correct |
51 ms |
1100 KB |
Output is correct |
40 |
Correct |
41 ms |
1156 KB |
Output is correct |
41 |
Correct |
38 ms |
1100 KB |
Output is correct |
42 |
Correct |
29 ms |
1100 KB |
Output is correct |
43 |
Correct |
44 ms |
1160 KB |
Output is correct |
44 |
Correct |
39 ms |
1164 KB |
Output is correct |
45 |
Correct |
39 ms |
1100 KB |
Output is correct |
46 |
Correct |
39 ms |
1176 KB |
Output is correct |
47 |
Correct |
36 ms |
1228 KB |
Output is correct |
48 |
Correct |
40 ms |
1168 KB |
Output is correct |
49 |
Correct |
46 ms |
1100 KB |
Output is correct |
50 |
Correct |
37 ms |
1180 KB |
Output is correct |
51 |
Correct |
35 ms |
1100 KB |
Output is correct |
52 |
Correct |
33 ms |
1168 KB |
Output is correct |
53 |
Correct |
37 ms |
1168 KB |
Output is correct |
54 |
Correct |
41 ms |
1172 KB |
Output is correct |
55 |
Incorrect |
45 ms |
2948 KB |
Output isn't correct |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
2 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
2 ms |
1100 KB |
Output is correct |
15 |
Correct |
2 ms |
1100 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
2 ms |
1100 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
2 ms |
1100 KB |
Output is correct |
20 |
Correct |
0 ms |
1100 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
2 ms |
1100 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
2 ms |
1100 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1064 KB |
Output is correct |
27 |
Correct |
1 ms |
1100 KB |
Output is correct |
28 |
Correct |
2 ms |
1100 KB |
Output is correct |
29 |
Correct |
33 ms |
1100 KB |
Output is correct |
30 |
Correct |
47 ms |
1100 KB |
Output is correct |
31 |
Correct |
42 ms |
1172 KB |
Output is correct |
32 |
Correct |
23 ms |
1100 KB |
Output is correct |
33 |
Correct |
15 ms |
1160 KB |
Output is correct |
34 |
Correct |
25 ms |
1172 KB |
Output is correct |
35 |
Correct |
42 ms |
1100 KB |
Output is correct |
36 |
Correct |
32 ms |
1164 KB |
Output is correct |
37 |
Correct |
63 ms |
1172 KB |
Output is correct |
38 |
Correct |
76 ms |
1176 KB |
Output is correct |
39 |
Correct |
51 ms |
1100 KB |
Output is correct |
40 |
Correct |
41 ms |
1156 KB |
Output is correct |
41 |
Correct |
38 ms |
1100 KB |
Output is correct |
42 |
Correct |
29 ms |
1100 KB |
Output is correct |
43 |
Correct |
44 ms |
1160 KB |
Output is correct |
44 |
Correct |
39 ms |
1164 KB |
Output is correct |
45 |
Correct |
39 ms |
1100 KB |
Output is correct |
46 |
Correct |
39 ms |
1176 KB |
Output is correct |
47 |
Correct |
36 ms |
1228 KB |
Output is correct |
48 |
Correct |
40 ms |
1168 KB |
Output is correct |
49 |
Correct |
46 ms |
1100 KB |
Output is correct |
50 |
Correct |
37 ms |
1180 KB |
Output is correct |
51 |
Correct |
35 ms |
1100 KB |
Output is correct |
52 |
Correct |
33 ms |
1168 KB |
Output is correct |
53 |
Correct |
37 ms |
1168 KB |
Output is correct |
54 |
Correct |
41 ms |
1172 KB |
Output is correct |
55 |
Correct |
119 ms |
6292 KB |
Output is correct |
56 |
Correct |
124 ms |
10268 KB |
Output is correct |
57 |
Correct |
118 ms |
10968 KB |
Output is correct |
58 |
Correct |
124 ms |
10248 KB |
Output is correct |
59 |
Correct |
118 ms |
10308 KB |
Output is correct |
60 |
Correct |
116 ms |
9500 KB |
Output is correct |
61 |
Correct |
112 ms |
9796 KB |
Output is correct |
62 |
Correct |
117 ms |
10436 KB |
Output is correct |
63 |
Correct |
119 ms |
10192 KB |
Output is correct |
64 |
Correct |
129 ms |
10764 KB |
Output is correct |
65 |
Correct |
121 ms |
9804 KB |
Output is correct |
66 |
Correct |
135 ms |
10096 KB |
Output is correct |
67 |
Correct |
146 ms |
10468 KB |
Output is correct |
68 |
Correct |
125 ms |
10824 KB |
Output is correct |
69 |
Incorrect |
84 ms |
8900 KB |
Output isn't correct |
70 |
Halted |
0 ms |
0 KB |
- |