#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];
struct xystate{
ll x,parx,relx,rnkx;
ll y,pary,rely,rnky;
xystate(ll ix,ll iparx,ll irelx,ll irnkx,
ll iy,ll ipary,ll irely,ll irnky){
x=ix,parx=iparx,relx=irelx,rnkx=irnkx;
y=iy,pary=ipary,rely=irely,rnky=irnky;
}
};
vector<xystate>sv;
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);
sv.push_back(xystate(x,par[x],rel[x],rnk[x],y,par[y],rel[y],rnk[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;
}
Compilation message
Joker.cpp: In function 'pl findset(ll*, ll*, ll)':
Joker.cpp:23:11: warning: unused variable 'og' [-Wunused-variable]
23 | ll cur=0,og=x;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 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 |
10060 KB |
Output is correct |
5 |
Correct |
6 ms |
10060 KB |
Output is correct |
6 |
Correct |
6 ms |
10060 KB |
Output is correct |
7 |
Correct |
9 ms |
10700 KB |
Output is correct |
8 |
Correct |
9 ms |
10704 KB |
Output is correct |
9 |
Correct |
7 ms |
10448 KB |
Output is correct |
10 |
Correct |
8 ms |
10444 KB |
Output is correct |
11 |
Correct |
7 ms |
10748 KB |
Output is correct |
12 |
Correct |
7 ms |
10704 KB |
Output is correct |
13 |
Correct |
8 ms |
10428 KB |
Output is correct |
14 |
Correct |
9 ms |
11212 KB |
Output is correct |
15 |
Correct |
9 ms |
11268 KB |
Output is correct |
16 |
Correct |
8 ms |
10440 KB |
Output is correct |
17 |
Correct |
7 ms |
10444 KB |
Output is correct |
18 |
Correct |
7 ms |
10448 KB |
Output is correct |
19 |
Correct |
6 ms |
10448 KB |
Output is correct |
20 |
Correct |
7 ms |
10316 KB |
Output is correct |
21 |
Correct |
7 ms |
10448 KB |
Output is correct |
22 |
Correct |
7 ms |
10704 KB |
Output is correct |
23 |
Correct |
7 ms |
10444 KB |
Output is correct |
24 |
Correct |
7 ms |
10448 KB |
Output is correct |
25 |
Correct |
7 ms |
10448 KB |
Output is correct |
26 |
Correct |
7 ms |
10316 KB |
Output is correct |
27 |
Correct |
7 ms |
10448 KB |
Output is correct |
28 |
Correct |
7 ms |
10796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 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 |
10060 KB |
Output is correct |
5 |
Correct |
6 ms |
10060 KB |
Output is correct |
6 |
Correct |
6 ms |
10060 KB |
Output is correct |
7 |
Correct |
9 ms |
10700 KB |
Output is correct |
8 |
Correct |
9 ms |
10704 KB |
Output is correct |
9 |
Correct |
7 ms |
10448 KB |
Output is correct |
10 |
Correct |
8 ms |
10444 KB |
Output is correct |
11 |
Correct |
7 ms |
10748 KB |
Output is correct |
12 |
Correct |
7 ms |
10704 KB |
Output is correct |
13 |
Correct |
8 ms |
10428 KB |
Output is correct |
14 |
Correct |
9 ms |
11212 KB |
Output is correct |
15 |
Correct |
9 ms |
11268 KB |
Output is correct |
16 |
Correct |
8 ms |
10440 KB |
Output is correct |
17 |
Correct |
7 ms |
10444 KB |
Output is correct |
18 |
Correct |
7 ms |
10448 KB |
Output is correct |
19 |
Correct |
6 ms |
10448 KB |
Output is correct |
20 |
Correct |
7 ms |
10316 KB |
Output is correct |
21 |
Correct |
7 ms |
10448 KB |
Output is correct |
22 |
Correct |
7 ms |
10704 KB |
Output is correct |
23 |
Correct |
7 ms |
10444 KB |
Output is correct |
24 |
Correct |
7 ms |
10448 KB |
Output is correct |
25 |
Correct |
7 ms |
10448 KB |
Output is correct |
26 |
Correct |
7 ms |
10316 KB |
Output is correct |
27 |
Correct |
7 ms |
10448 KB |
Output is correct |
28 |
Correct |
7 ms |
10796 KB |
Output is correct |
29 |
Correct |
49 ms |
43240 KB |
Output is correct |
30 |
Correct |
49 ms |
43312 KB |
Output is correct |
31 |
Correct |
52 ms |
43256 KB |
Output is correct |
32 |
Correct |
34 ms |
26796 KB |
Output is correct |
33 |
Correct |
20 ms |
18524 KB |
Output is correct |
34 |
Correct |
51 ms |
43176 KB |
Output is correct |
35 |
Correct |
58 ms |
43228 KB |
Output is correct |
36 |
Correct |
32 ms |
26812 KB |
Output is correct |
37 |
Correct |
81 ms |
76044 KB |
Output is correct |
38 |
Correct |
157 ms |
141732 KB |
Output is correct |
39 |
Correct |
30 ms |
26784 KB |
Output is correct |
40 |
Correct |
32 ms |
26732 KB |
Output is correct |
41 |
Correct |
31 ms |
26832 KB |
Output is correct |
42 |
Correct |
31 ms |
26804 KB |
Output is correct |
43 |
Correct |
44 ms |
26756 KB |
Output is correct |
44 |
Correct |
63 ms |
43144 KB |
Output is correct |
45 |
Correct |
89 ms |
76080 KB |
Output is correct |
46 |
Correct |
102 ms |
76008 KB |
Output is correct |
47 |
Correct |
32 ms |
26824 KB |
Output is correct |
48 |
Correct |
36 ms |
26720 KB |
Output is correct |
49 |
Correct |
50 ms |
43248 KB |
Output is correct |
50 |
Correct |
49 ms |
43200 KB |
Output is correct |
51 |
Correct |
27 ms |
18508 KB |
Output is correct |
52 |
Correct |
38 ms |
26820 KB |
Output is correct |
53 |
Correct |
51 ms |
43228 KB |
Output is correct |
54 |
Correct |
56 ms |
43288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
10060 KB |
Output is correct |
2 |
Correct |
7 ms |
10060 KB |
Output is correct |
3 |
Execution timed out |
2085 ms |
24016 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 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 |
10060 KB |
Output is correct |
5 |
Correct |
6 ms |
10060 KB |
Output is correct |
6 |
Correct |
6 ms |
10060 KB |
Output is correct |
7 |
Correct |
9 ms |
10700 KB |
Output is correct |
8 |
Correct |
9 ms |
10704 KB |
Output is correct |
9 |
Correct |
7 ms |
10448 KB |
Output is correct |
10 |
Correct |
8 ms |
10444 KB |
Output is correct |
11 |
Correct |
7 ms |
10748 KB |
Output is correct |
12 |
Correct |
7 ms |
10704 KB |
Output is correct |
13 |
Correct |
8 ms |
10428 KB |
Output is correct |
14 |
Correct |
9 ms |
11212 KB |
Output is correct |
15 |
Correct |
9 ms |
11268 KB |
Output is correct |
16 |
Correct |
8 ms |
10440 KB |
Output is correct |
17 |
Correct |
7 ms |
10444 KB |
Output is correct |
18 |
Correct |
7 ms |
10448 KB |
Output is correct |
19 |
Correct |
6 ms |
10448 KB |
Output is correct |
20 |
Correct |
7 ms |
10316 KB |
Output is correct |
21 |
Correct |
7 ms |
10448 KB |
Output is correct |
22 |
Correct |
7 ms |
10704 KB |
Output is correct |
23 |
Correct |
7 ms |
10444 KB |
Output is correct |
24 |
Correct |
7 ms |
10448 KB |
Output is correct |
25 |
Correct |
7 ms |
10448 KB |
Output is correct |
26 |
Correct |
7 ms |
10316 KB |
Output is correct |
27 |
Correct |
7 ms |
10448 KB |
Output is correct |
28 |
Correct |
7 ms |
10796 KB |
Output is correct |
29 |
Execution timed out |
2085 ms |
24016 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 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 |
10060 KB |
Output is correct |
5 |
Correct |
6 ms |
10060 KB |
Output is correct |
6 |
Correct |
6 ms |
10060 KB |
Output is correct |
7 |
Correct |
9 ms |
10700 KB |
Output is correct |
8 |
Correct |
9 ms |
10704 KB |
Output is correct |
9 |
Correct |
7 ms |
10448 KB |
Output is correct |
10 |
Correct |
8 ms |
10444 KB |
Output is correct |
11 |
Correct |
7 ms |
10748 KB |
Output is correct |
12 |
Correct |
7 ms |
10704 KB |
Output is correct |
13 |
Correct |
8 ms |
10428 KB |
Output is correct |
14 |
Correct |
9 ms |
11212 KB |
Output is correct |
15 |
Correct |
9 ms |
11268 KB |
Output is correct |
16 |
Correct |
8 ms |
10440 KB |
Output is correct |
17 |
Correct |
7 ms |
10444 KB |
Output is correct |
18 |
Correct |
7 ms |
10448 KB |
Output is correct |
19 |
Correct |
6 ms |
10448 KB |
Output is correct |
20 |
Correct |
7 ms |
10316 KB |
Output is correct |
21 |
Correct |
7 ms |
10448 KB |
Output is correct |
22 |
Correct |
7 ms |
10704 KB |
Output is correct |
23 |
Correct |
7 ms |
10444 KB |
Output is correct |
24 |
Correct |
7 ms |
10448 KB |
Output is correct |
25 |
Correct |
7 ms |
10448 KB |
Output is correct |
26 |
Correct |
7 ms |
10316 KB |
Output is correct |
27 |
Correct |
7 ms |
10448 KB |
Output is correct |
28 |
Correct |
7 ms |
10796 KB |
Output is correct |
29 |
Correct |
49 ms |
43240 KB |
Output is correct |
30 |
Correct |
49 ms |
43312 KB |
Output is correct |
31 |
Correct |
52 ms |
43256 KB |
Output is correct |
32 |
Correct |
34 ms |
26796 KB |
Output is correct |
33 |
Correct |
20 ms |
18524 KB |
Output is correct |
34 |
Correct |
51 ms |
43176 KB |
Output is correct |
35 |
Correct |
58 ms |
43228 KB |
Output is correct |
36 |
Correct |
32 ms |
26812 KB |
Output is correct |
37 |
Correct |
81 ms |
76044 KB |
Output is correct |
38 |
Correct |
157 ms |
141732 KB |
Output is correct |
39 |
Correct |
30 ms |
26784 KB |
Output is correct |
40 |
Correct |
32 ms |
26732 KB |
Output is correct |
41 |
Correct |
31 ms |
26832 KB |
Output is correct |
42 |
Correct |
31 ms |
26804 KB |
Output is correct |
43 |
Correct |
44 ms |
26756 KB |
Output is correct |
44 |
Correct |
63 ms |
43144 KB |
Output is correct |
45 |
Correct |
89 ms |
76080 KB |
Output is correct |
46 |
Correct |
102 ms |
76008 KB |
Output is correct |
47 |
Correct |
32 ms |
26824 KB |
Output is correct |
48 |
Correct |
36 ms |
26720 KB |
Output is correct |
49 |
Correct |
50 ms |
43248 KB |
Output is correct |
50 |
Correct |
49 ms |
43200 KB |
Output is correct |
51 |
Correct |
27 ms |
18508 KB |
Output is correct |
52 |
Correct |
38 ms |
26820 KB |
Output is correct |
53 |
Correct |
51 ms |
43228 KB |
Output is correct |
54 |
Correct |
56 ms |
43288 KB |
Output is correct |
55 |
Runtime error |
347 ms |
262148 KB |
Execution killed with signal 9 |
56 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 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 |
10060 KB |
Output is correct |
5 |
Correct |
6 ms |
10060 KB |
Output is correct |
6 |
Correct |
6 ms |
10060 KB |
Output is correct |
7 |
Correct |
9 ms |
10700 KB |
Output is correct |
8 |
Correct |
9 ms |
10704 KB |
Output is correct |
9 |
Correct |
7 ms |
10448 KB |
Output is correct |
10 |
Correct |
8 ms |
10444 KB |
Output is correct |
11 |
Correct |
7 ms |
10748 KB |
Output is correct |
12 |
Correct |
7 ms |
10704 KB |
Output is correct |
13 |
Correct |
8 ms |
10428 KB |
Output is correct |
14 |
Correct |
9 ms |
11212 KB |
Output is correct |
15 |
Correct |
9 ms |
11268 KB |
Output is correct |
16 |
Correct |
8 ms |
10440 KB |
Output is correct |
17 |
Correct |
7 ms |
10444 KB |
Output is correct |
18 |
Correct |
7 ms |
10448 KB |
Output is correct |
19 |
Correct |
6 ms |
10448 KB |
Output is correct |
20 |
Correct |
7 ms |
10316 KB |
Output is correct |
21 |
Correct |
7 ms |
10448 KB |
Output is correct |
22 |
Correct |
7 ms |
10704 KB |
Output is correct |
23 |
Correct |
7 ms |
10444 KB |
Output is correct |
24 |
Correct |
7 ms |
10448 KB |
Output is correct |
25 |
Correct |
7 ms |
10448 KB |
Output is correct |
26 |
Correct |
7 ms |
10316 KB |
Output is correct |
27 |
Correct |
7 ms |
10448 KB |
Output is correct |
28 |
Correct |
7 ms |
10796 KB |
Output is correct |
29 |
Correct |
49 ms |
43240 KB |
Output is correct |
30 |
Correct |
49 ms |
43312 KB |
Output is correct |
31 |
Correct |
52 ms |
43256 KB |
Output is correct |
32 |
Correct |
34 ms |
26796 KB |
Output is correct |
33 |
Correct |
20 ms |
18524 KB |
Output is correct |
34 |
Correct |
51 ms |
43176 KB |
Output is correct |
35 |
Correct |
58 ms |
43228 KB |
Output is correct |
36 |
Correct |
32 ms |
26812 KB |
Output is correct |
37 |
Correct |
81 ms |
76044 KB |
Output is correct |
38 |
Correct |
157 ms |
141732 KB |
Output is correct |
39 |
Correct |
30 ms |
26784 KB |
Output is correct |
40 |
Correct |
32 ms |
26732 KB |
Output is correct |
41 |
Correct |
31 ms |
26832 KB |
Output is correct |
42 |
Correct |
31 ms |
26804 KB |
Output is correct |
43 |
Correct |
44 ms |
26756 KB |
Output is correct |
44 |
Correct |
63 ms |
43144 KB |
Output is correct |
45 |
Correct |
89 ms |
76080 KB |
Output is correct |
46 |
Correct |
102 ms |
76008 KB |
Output is correct |
47 |
Correct |
32 ms |
26824 KB |
Output is correct |
48 |
Correct |
36 ms |
26720 KB |
Output is correct |
49 |
Correct |
50 ms |
43248 KB |
Output is correct |
50 |
Correct |
49 ms |
43200 KB |
Output is correct |
51 |
Correct |
27 ms |
18508 KB |
Output is correct |
52 |
Correct |
38 ms |
26820 KB |
Output is correct |
53 |
Correct |
51 ms |
43228 KB |
Output is correct |
54 |
Correct |
56 ms |
43288 KB |
Output is correct |
55 |
Execution timed out |
2085 ms |
24016 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |