#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<ll,pl> ppl;
const ll lim=4e5+5;
ll par[lim],rnk[lim],rel[lim];
ll parcpy[lim],rnkcpy[lim],relcpy[lim];
pl findset(ll par[],ll rel[],ll x){
ll cur=0,og=x;
while(x!=par[x]){
if(rel[x])cur=1-cur;
x=par[x];
}
par[og]=x;
rel[og]=cur;
return {x,cur};
}
void mergeset(ll par[],ll rnk[],ll rel[],ll x,ll y){
pl px=findset(par,rel,x),py=findset(par,rel,y);
x=px.first,y=py.first;
if(x==y)return;
if(rnk[x]>rnk[y])swap(x,y);
if(rnk[x]==rnk[y])rnk[y]++;
par[x]=y;
rnk[y]++;
rel[x]=(px.second==py.second);
return;
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(NULL);
ll n,m,q;
cin>>n>>m>>q;
for(int i=1;i<=n;i++)par[i]=i;
vector<pl>v;
vector<pl>qs[lim];
for(int i=0;i<m;i++){
ll a,b;
cin>>a>>b;
v.emplace_back(a,b);
}
//v.emplace_back(0,0);
bool ans[lim],cfa=0;
fill(ans,ans+lim,0);
for(int i=0;i<q;i++){
ll a,b;
cin>>a>>b;
b--,b++;//b is the minimum index that can be used on the right side
qs[b].emplace_back(a,i);
}
for(int i=m;i>=m;i--){
sort(qs[i].begin(),qs[i].end());
for(int i=1;i<=n;i++)parcpy[i]=par[i],rnkcpy[i]=rnk[i],relcpy[i]=rel[i];
ll cur=0;
bool oddc=0;
for(auto x:qs[i]){
if(oddc==1){
ans[x.second]=1;
continue;
}
for(;cur+1<x.first;cur++){
pl x=findset(parcpy,relcpy,v[cur].first),y=findset(parcpy,relcpy,v[cur].second);
if(x.first==y.first){
if(x.second==y.second){
oddc=1;
}
}
else mergeset(parcpy,rnkcpy,relcpy,v[cur].first,v[cur].second);
}
ans[x.second]=oddc;
}
}
for(int i=m-1;i>=1;i--){
if(cfa==1){
for(auto x:qs[i])ans[x.second]=1;
continue;
}
pl x=findset(par,rel,v[i].first),y=findset(par,rel,v[i].second);
if(x.first==y.first){
if(x.second==y.second){
cfa=1;
}
}
else mergeset(par,rnk,rel,v[i].first,v[i].second);
if(qs[i].empty())continue;
if(cfa==1){
for(auto x:qs[i])ans[x.second]=1;
continue;
}
sort(qs[i].begin(),qs[i].end());
for(int i=1;i<=n;i++)parcpy[i]=par[i],rnkcpy[i]=rnk[i],relcpy[i]=rel[i];
ll cur=0;
bool oddc=0;
for(auto x:qs[i]){
if(oddc==1){
ans[x.second]=1;
continue;
}
for(;cur+1<x.first;cur++){
pl x=findset(parcpy,relcpy,v[cur].first),y=findset(parcpy,relcpy,v[cur].second);
if(x.first==y.first){
if(x.second==y.second){
oddc=1;
}
}
else mergeset(parcpy,rnkcpy,relcpy,v[cur].first,v[cur].second);
}
ans[x.second]=oddc;
}
}
for(int i=0;i<q;i++){
if(ans[i])cout<<"YES\n";
else cout<<"NO\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10060 KB |
Output is correct |
2 |
Correct |
7 ms |
10060 KB |
Output is correct |
3 |
Correct |
7 ms |
10060 KB |
Output is correct |
4 |
Correct |
6 ms |
10136 KB |
Output is correct |
5 |
Correct |
6 ms |
10068 KB |
Output is correct |
6 |
Correct |
7 ms |
10140 KB |
Output is correct |
7 |
Correct |
7 ms |
10060 KB |
Output is correct |
8 |
Correct |
7 ms |
10060 KB |
Output is correct |
9 |
Correct |
7 ms |
10168 KB |
Output is correct |
10 |
Correct |
8 ms |
10060 KB |
Output is correct |
11 |
Correct |
7 ms |
10060 KB |
Output is correct |
12 |
Correct |
7 ms |
10060 KB |
Output is correct |
13 |
Correct |
8 ms |
10160 KB |
Output is correct |
14 |
Correct |
7 ms |
10060 KB |
Output is correct |
15 |
Correct |
7 ms |
10172 KB |
Output is correct |
16 |
Correct |
7 ms |
10064 KB |
Output is correct |
17 |
Correct |
7 ms |
10104 KB |
Output is correct |
18 |
Correct |
7 ms |
10060 KB |
Output is correct |
19 |
Correct |
7 ms |
10060 KB |
Output is correct |
20 |
Correct |
7 ms |
10060 KB |
Output is correct |
21 |
Correct |
7 ms |
10060 KB |
Output is correct |
22 |
Correct |
7 ms |
10060 KB |
Output is correct |
23 |
Correct |
7 ms |
10060 KB |
Output is correct |
24 |
Correct |
7 ms |
10168 KB |
Output is correct |
25 |
Correct |
7 ms |
10060 KB |
Output is correct |
26 |
Correct |
7 ms |
10160 KB |
Output is correct |
27 |
Correct |
7 ms |
10060 KB |
Output is correct |
28 |
Correct |
7 ms |
10060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10060 KB |
Output is correct |
2 |
Correct |
7 ms |
10060 KB |
Output is correct |
3 |
Correct |
7 ms |
10060 KB |
Output is correct |
4 |
Correct |
6 ms |
10136 KB |
Output is correct |
5 |
Correct |
6 ms |
10068 KB |
Output is correct |
6 |
Correct |
7 ms |
10140 KB |
Output is correct |
7 |
Correct |
7 ms |
10060 KB |
Output is correct |
8 |
Correct |
7 ms |
10060 KB |
Output is correct |
9 |
Correct |
7 ms |
10168 KB |
Output is correct |
10 |
Correct |
8 ms |
10060 KB |
Output is correct |
11 |
Correct |
7 ms |
10060 KB |
Output is correct |
12 |
Correct |
7 ms |
10060 KB |
Output is correct |
13 |
Correct |
8 ms |
10160 KB |
Output is correct |
14 |
Correct |
7 ms |
10060 KB |
Output is correct |
15 |
Correct |
7 ms |
10172 KB |
Output is correct |
16 |
Correct |
7 ms |
10064 KB |
Output is correct |
17 |
Correct |
7 ms |
10104 KB |
Output is correct |
18 |
Correct |
7 ms |
10060 KB |
Output is correct |
19 |
Correct |
7 ms |
10060 KB |
Output is correct |
20 |
Correct |
7 ms |
10060 KB |
Output is correct |
21 |
Correct |
7 ms |
10060 KB |
Output is correct |
22 |
Correct |
7 ms |
10060 KB |
Output is correct |
23 |
Correct |
7 ms |
10060 KB |
Output is correct |
24 |
Correct |
7 ms |
10168 KB |
Output is correct |
25 |
Correct |
7 ms |
10060 KB |
Output is correct |
26 |
Correct |
7 ms |
10160 KB |
Output is correct |
27 |
Correct |
7 ms |
10060 KB |
Output is correct |
28 |
Correct |
7 ms |
10060 KB |
Output is correct |
29 |
Correct |
22 ms |
10316 KB |
Output is correct |
30 |
Correct |
22 ms |
10356 KB |
Output is correct |
31 |
Correct |
24 ms |
10340 KB |
Output is correct |
32 |
Correct |
18 ms |
10232 KB |
Output is correct |
33 |
Correct |
13 ms |
10316 KB |
Output is correct |
34 |
Correct |
23 ms |
10368 KB |
Output is correct |
35 |
Correct |
25 ms |
10368 KB |
Output is correct |
36 |
Correct |
16 ms |
10224 KB |
Output is correct |
37 |
Correct |
27 ms |
10368 KB |
Output is correct |
38 |
Correct |
47 ms |
10356 KB |
Output is correct |
39 |
Correct |
15 ms |
10316 KB |
Output is correct |
40 |
Correct |
17 ms |
10316 KB |
Output is correct |
41 |
Correct |
17 ms |
10312 KB |
Output is correct |
42 |
Correct |
20 ms |
10316 KB |
Output is correct |
43 |
Correct |
26 ms |
10188 KB |
Output is correct |
44 |
Correct |
29 ms |
10188 KB |
Output is correct |
45 |
Correct |
35 ms |
10344 KB |
Output is correct |
46 |
Correct |
41 ms |
10316 KB |
Output is correct |
47 |
Correct |
18 ms |
10188 KB |
Output is correct |
48 |
Correct |
19 ms |
10316 KB |
Output is correct |
49 |
Correct |
22 ms |
10316 KB |
Output is correct |
50 |
Correct |
22 ms |
10364 KB |
Output is correct |
51 |
Correct |
17 ms |
10320 KB |
Output is correct |
52 |
Correct |
20 ms |
10380 KB |
Output is correct |
53 |
Correct |
22 ms |
10324 KB |
Output is correct |
54 |
Correct |
25 ms |
10316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10060 KB |
Output is correct |
2 |
Correct |
7 ms |
10060 KB |
Output is correct |
3 |
Execution timed out |
2070 ms |
23092 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10060 KB |
Output is correct |
2 |
Correct |
7 ms |
10060 KB |
Output is correct |
3 |
Correct |
7 ms |
10060 KB |
Output is correct |
4 |
Correct |
6 ms |
10136 KB |
Output is correct |
5 |
Correct |
6 ms |
10068 KB |
Output is correct |
6 |
Correct |
7 ms |
10140 KB |
Output is correct |
7 |
Correct |
7 ms |
10060 KB |
Output is correct |
8 |
Correct |
7 ms |
10060 KB |
Output is correct |
9 |
Correct |
7 ms |
10168 KB |
Output is correct |
10 |
Correct |
8 ms |
10060 KB |
Output is correct |
11 |
Correct |
7 ms |
10060 KB |
Output is correct |
12 |
Correct |
7 ms |
10060 KB |
Output is correct |
13 |
Correct |
8 ms |
10160 KB |
Output is correct |
14 |
Correct |
7 ms |
10060 KB |
Output is correct |
15 |
Correct |
7 ms |
10172 KB |
Output is correct |
16 |
Correct |
7 ms |
10064 KB |
Output is correct |
17 |
Correct |
7 ms |
10104 KB |
Output is correct |
18 |
Correct |
7 ms |
10060 KB |
Output is correct |
19 |
Correct |
7 ms |
10060 KB |
Output is correct |
20 |
Correct |
7 ms |
10060 KB |
Output is correct |
21 |
Correct |
7 ms |
10060 KB |
Output is correct |
22 |
Correct |
7 ms |
10060 KB |
Output is correct |
23 |
Correct |
7 ms |
10060 KB |
Output is correct |
24 |
Correct |
7 ms |
10168 KB |
Output is correct |
25 |
Correct |
7 ms |
10060 KB |
Output is correct |
26 |
Correct |
7 ms |
10160 KB |
Output is correct |
27 |
Correct |
7 ms |
10060 KB |
Output is correct |
28 |
Correct |
7 ms |
10060 KB |
Output is correct |
29 |
Execution timed out |
2070 ms |
23092 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10060 KB |
Output is correct |
2 |
Correct |
7 ms |
10060 KB |
Output is correct |
3 |
Correct |
7 ms |
10060 KB |
Output is correct |
4 |
Correct |
6 ms |
10136 KB |
Output is correct |
5 |
Correct |
6 ms |
10068 KB |
Output is correct |
6 |
Correct |
7 ms |
10140 KB |
Output is correct |
7 |
Correct |
7 ms |
10060 KB |
Output is correct |
8 |
Correct |
7 ms |
10060 KB |
Output is correct |
9 |
Correct |
7 ms |
10168 KB |
Output is correct |
10 |
Correct |
8 ms |
10060 KB |
Output is correct |
11 |
Correct |
7 ms |
10060 KB |
Output is correct |
12 |
Correct |
7 ms |
10060 KB |
Output is correct |
13 |
Correct |
8 ms |
10160 KB |
Output is correct |
14 |
Correct |
7 ms |
10060 KB |
Output is correct |
15 |
Correct |
7 ms |
10172 KB |
Output is correct |
16 |
Correct |
7 ms |
10064 KB |
Output is correct |
17 |
Correct |
7 ms |
10104 KB |
Output is correct |
18 |
Correct |
7 ms |
10060 KB |
Output is correct |
19 |
Correct |
7 ms |
10060 KB |
Output is correct |
20 |
Correct |
7 ms |
10060 KB |
Output is correct |
21 |
Correct |
7 ms |
10060 KB |
Output is correct |
22 |
Correct |
7 ms |
10060 KB |
Output is correct |
23 |
Correct |
7 ms |
10060 KB |
Output is correct |
24 |
Correct |
7 ms |
10168 KB |
Output is correct |
25 |
Correct |
7 ms |
10060 KB |
Output is correct |
26 |
Correct |
7 ms |
10160 KB |
Output is correct |
27 |
Correct |
7 ms |
10060 KB |
Output is correct |
28 |
Correct |
7 ms |
10060 KB |
Output is correct |
29 |
Correct |
22 ms |
10316 KB |
Output is correct |
30 |
Correct |
22 ms |
10356 KB |
Output is correct |
31 |
Correct |
24 ms |
10340 KB |
Output is correct |
32 |
Correct |
18 ms |
10232 KB |
Output is correct |
33 |
Correct |
13 ms |
10316 KB |
Output is correct |
34 |
Correct |
23 ms |
10368 KB |
Output is correct |
35 |
Correct |
25 ms |
10368 KB |
Output is correct |
36 |
Correct |
16 ms |
10224 KB |
Output is correct |
37 |
Correct |
27 ms |
10368 KB |
Output is correct |
38 |
Correct |
47 ms |
10356 KB |
Output is correct |
39 |
Correct |
15 ms |
10316 KB |
Output is correct |
40 |
Correct |
17 ms |
10316 KB |
Output is correct |
41 |
Correct |
17 ms |
10312 KB |
Output is correct |
42 |
Correct |
20 ms |
10316 KB |
Output is correct |
43 |
Correct |
26 ms |
10188 KB |
Output is correct |
44 |
Correct |
29 ms |
10188 KB |
Output is correct |
45 |
Correct |
35 ms |
10344 KB |
Output is correct |
46 |
Correct |
41 ms |
10316 KB |
Output is correct |
47 |
Correct |
18 ms |
10188 KB |
Output is correct |
48 |
Correct |
19 ms |
10316 KB |
Output is correct |
49 |
Correct |
22 ms |
10316 KB |
Output is correct |
50 |
Correct |
22 ms |
10364 KB |
Output is correct |
51 |
Correct |
17 ms |
10320 KB |
Output is correct |
52 |
Correct |
20 ms |
10380 KB |
Output is correct |
53 |
Correct |
22 ms |
10324 KB |
Output is correct |
54 |
Correct |
25 ms |
10316 KB |
Output is correct |
55 |
Execution timed out |
2075 ms |
19600 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
10060 KB |
Output is correct |
2 |
Correct |
7 ms |
10060 KB |
Output is correct |
3 |
Correct |
7 ms |
10060 KB |
Output is correct |
4 |
Correct |
6 ms |
10136 KB |
Output is correct |
5 |
Correct |
6 ms |
10068 KB |
Output is correct |
6 |
Correct |
7 ms |
10140 KB |
Output is correct |
7 |
Correct |
7 ms |
10060 KB |
Output is correct |
8 |
Correct |
7 ms |
10060 KB |
Output is correct |
9 |
Correct |
7 ms |
10168 KB |
Output is correct |
10 |
Correct |
8 ms |
10060 KB |
Output is correct |
11 |
Correct |
7 ms |
10060 KB |
Output is correct |
12 |
Correct |
7 ms |
10060 KB |
Output is correct |
13 |
Correct |
8 ms |
10160 KB |
Output is correct |
14 |
Correct |
7 ms |
10060 KB |
Output is correct |
15 |
Correct |
7 ms |
10172 KB |
Output is correct |
16 |
Correct |
7 ms |
10064 KB |
Output is correct |
17 |
Correct |
7 ms |
10104 KB |
Output is correct |
18 |
Correct |
7 ms |
10060 KB |
Output is correct |
19 |
Correct |
7 ms |
10060 KB |
Output is correct |
20 |
Correct |
7 ms |
10060 KB |
Output is correct |
21 |
Correct |
7 ms |
10060 KB |
Output is correct |
22 |
Correct |
7 ms |
10060 KB |
Output is correct |
23 |
Correct |
7 ms |
10060 KB |
Output is correct |
24 |
Correct |
7 ms |
10168 KB |
Output is correct |
25 |
Correct |
7 ms |
10060 KB |
Output is correct |
26 |
Correct |
7 ms |
10160 KB |
Output is correct |
27 |
Correct |
7 ms |
10060 KB |
Output is correct |
28 |
Correct |
7 ms |
10060 KB |
Output is correct |
29 |
Correct |
22 ms |
10316 KB |
Output is correct |
30 |
Correct |
22 ms |
10356 KB |
Output is correct |
31 |
Correct |
24 ms |
10340 KB |
Output is correct |
32 |
Correct |
18 ms |
10232 KB |
Output is correct |
33 |
Correct |
13 ms |
10316 KB |
Output is correct |
34 |
Correct |
23 ms |
10368 KB |
Output is correct |
35 |
Correct |
25 ms |
10368 KB |
Output is correct |
36 |
Correct |
16 ms |
10224 KB |
Output is correct |
37 |
Correct |
27 ms |
10368 KB |
Output is correct |
38 |
Correct |
47 ms |
10356 KB |
Output is correct |
39 |
Correct |
15 ms |
10316 KB |
Output is correct |
40 |
Correct |
17 ms |
10316 KB |
Output is correct |
41 |
Correct |
17 ms |
10312 KB |
Output is correct |
42 |
Correct |
20 ms |
10316 KB |
Output is correct |
43 |
Correct |
26 ms |
10188 KB |
Output is correct |
44 |
Correct |
29 ms |
10188 KB |
Output is correct |
45 |
Correct |
35 ms |
10344 KB |
Output is correct |
46 |
Correct |
41 ms |
10316 KB |
Output is correct |
47 |
Correct |
18 ms |
10188 KB |
Output is correct |
48 |
Correct |
19 ms |
10316 KB |
Output is correct |
49 |
Correct |
22 ms |
10316 KB |
Output is correct |
50 |
Correct |
22 ms |
10364 KB |
Output is correct |
51 |
Correct |
17 ms |
10320 KB |
Output is correct |
52 |
Correct |
20 ms |
10380 KB |
Output is correct |
53 |
Correct |
22 ms |
10324 KB |
Output is correct |
54 |
Correct |
25 ms |
10316 KB |
Output is correct |
55 |
Execution timed out |
2070 ms |
23092 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |