#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include "bits/stdc++.h"
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
//using namespace __gnu_pbds;
/*
ll add(ll x,ll y){
x+=y;
if(x<0){
x%=mod;
x+=mod;
}else{
if(x>=mod) x%=mod;
}
return x;
}
ll mul(ll a,ll b){
ll ans = (a*b)%mod;
if(ans<0) ans+=mod;
return ans;
}
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
return uniform_int_distribution<ll>(l,r)(rng);
}
*/
#define maxn 200005
ll n,m,q;
pll e[maxn];
ll dsu[maxn],sizi[maxn];
ll last[maxn];
ll root(ll x){
while(x!=dsu[x]) x = dsu[x];
return x;
}
ll col(ll x){
ll cnt = 0;
while(x!=dsu[x]){cnt++;x = dsu[x];}
return cnt&1;
}
stack<pll> st;
ll cnt = 0;
void upd(ll u,ll v){
if(u+v==0) return;
if(root(u)==root(v)){
if(col(u)==col(v)) cnt++;
st.push({-v,-u});
}else{
u = root(u);
v = root(v);
if(sizi[u]>sizi[v]) swap(u,v);
sizi[u]+=sizi[v];
dsu[v] = u;
st.push({v,u});
}
}
void roll(){
if(st.empty()) return;
ll v = st.top().fi;
ll u = st.top().sc;
st.pop();
bool f = (v<0);
if(f) v = -v,u = -u;
if(!f){
sizi[u]-=sizi[v];
dsu[v] = v;
}else{
if(col(u)==col(v)) cnt--;
}
}
void reshi(ll l,ll r,ll tl,ll tr){
if(l>r) return;
ll mid = (l+r)/2;
for(ll i = l;i<mid;i++){
upd(e[i].fi,e[i].sc);
}
ll i = tr;
if(cnt) last[mid] = m+1;
while(!cnt&&i>=max(mid,tl)){
upd(e[i].fi,e[i].sc);
i--;
}
if(!last[mid]) last[mid] = i+1;
if(i==mid-1) last[mid] = m+1;
for(ll j = i+1;j<=tr;j++) roll();
upd(e[mid].fi,e[mid].sc);
cerr<<sz(st)<< " "<<cnt<< " "<<l<< " "<<r<< " "<<tl<< " "<<tr<<" "<<last[mid]<<endl;
reshi(mid+1,r,max(mid+1,last[mid]),tr);
for(ll j = l;j<=mid;j++) roll();
for(ll j = last[mid]+1;j<=tr;j++) upd(e[j].fi,e[j].sc);
reshi(l,mid-1,tl,last[mid]);
for(ll j = last[mid]+1;j<=tr;j++) roll();
}
void tc(){
cin >> n >> m >> q;
for(ll i = 1;i<=m;i++) cin >> e[i].fi >> e[i].sc;
iota(dsu+1,dsu+1+n,1);
reshi(1,m,1,m);
ceri(last,1,m);
while(q--){
ll l,r; cin >> l >> r;
if(last[l]>r) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
int main(){
daj_mi_malo_vremena
int t; t = 1;
while(t--){
tc();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |