#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define all(x) x.begin(), x.end()
const int N=200005;
const int M=500005;
const int INF=1e9;
const int mod=1e9+7;
vector<int> e1(N<<1),e2(N<<1);
vector<int> pa(N<<1),sz(N<<1,1);
vector<int> dp(N);
vector<tuple<int,int,int,int>> st;
vector<int> st1;
int valid=0;
int Find(int k){
if(pa[k]==k){
return k;
}
return pa[k]=Find(pa[k]);
}
void onion2(int a,int b){
//cout<<"onion "<<a<<' '<<b<<endl;
a=Find(a);
b=Find(b);
if(a==b){
return;
}
if(sz[a]>sz[b]){
swap(a,b);
}
st.push_back({a,pa[a],b,sz[b]});
pa[a]=b;
sz[b]+=sz[a];
}
int onion1(int a,int b){
onion2(a,b+N);
onion2(a+N,b);
while(st.size()>st1.size()){
st1.push_back(valid);
}
valid|=(Find(a)==Find(a+N));
return valid;
}
int onion(int i){
return onion1(e1[i],e2[i]);
}
void undo(){
auto [a,b,c,d]=st.back();
st.pop_back();
pa[a]=b;
sz[c]=d;
valid=st1.back();
st1.pop_back();
}
// | 1 2 3 4 | 5 6 7 8
void dc(int l,int r,int a,int b){
if(r<=l)return;
a=max(a,1);
b=max(b,a);
//cout<<l<<' '<<r<<' '<<a<<' '<<b<<endl;
int m=(l+r)>>1;
int flag=0;
int rec1=st.size();
for(int i=l;i<=m;i++){
flag|=onion(i);
}
int rec=st.size();
if(flag){
dp[m]=b+1;
}
else{
int last=b;
for(int i=b;i>=a;i--){
if(onion(i)){
break;
}
last--;
}
dp[m]=last;
}
while(st.size()>rec){
undo();
}
dc(m+1,r,dp[m],b);
while(st.size()>rec1){
undo();
}
for(int i=b;i>dp[m];i--){
onion(i);
}
dc(l,m,a,dp[m]);
while(st.size()>rec1){
undo();
}
}
int32_t main() {
LCBorz;
iota(all(pa),0);
int n,m,q;cin>>n>>m>>q;
e1[0]=N-1,e2[0]=1;
for(int i=1;i<=m;i++){
cin>>e1[i]>>e2[i];
}
dc(0,m+1,1,m);
for(int i=0;i<q;i++){
int a,b;cin>>a>>b;
if(b>=dp[a-1]){
cout<<"NO"<<endl;
}
else{
cout<<"YES"<<endl;
}
}
return 0;
}
Compilation message
Joker.cpp: In function 'void dc(int, int, int, int)':
Joker.cpp:81:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::tuple<int, int, int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
81 | while(st.size()>rec){
| ~~~~~~~~~^~~~
Joker.cpp:85:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::tuple<int, int, int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
85 | while(st.size()>rec1){
| ~~~~~~~~~^~~~~
Joker.cpp:92:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::tuple<int, int, int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
92 | while(st.size()>rec1){
| ~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7516 KB |
Output is correct |
3 |
Correct |
4 ms |
7516 KB |
Output is correct |
4 |
Correct |
4 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Incorrect |
4 ms |
7516 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7516 KB |
Output is correct |
3 |
Correct |
4 ms |
7516 KB |
Output is correct |
4 |
Correct |
4 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Incorrect |
4 ms |
7516 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7516 KB |
Output is correct |
3 |
Incorrect |
354 ms |
17328 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7516 KB |
Output is correct |
3 |
Correct |
4 ms |
7516 KB |
Output is correct |
4 |
Correct |
4 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Incorrect |
4 ms |
7516 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7516 KB |
Output is correct |
3 |
Correct |
4 ms |
7516 KB |
Output is correct |
4 |
Correct |
4 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Incorrect |
4 ms |
7516 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7516 KB |
Output is correct |
2 |
Correct |
4 ms |
7516 KB |
Output is correct |
3 |
Correct |
4 ms |
7516 KB |
Output is correct |
4 |
Correct |
4 ms |
7516 KB |
Output is correct |
5 |
Correct |
4 ms |
7516 KB |
Output is correct |
6 |
Incorrect |
4 ms |
7516 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |