Submission #660218

# Submission time Handle Problem Language Result Execution time Memory
660218 2022-11-21T07:19:18 Z zaneyu Joker (BOI20_joker) C++14
0 / 100
53 ms 22328 KB
/*input
6 8 2
1 3
1 5
1 6
2 5
2 6
3 4
3 5
5 6
4 8
4 7
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace __gnu_pbds;
typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key #of elements less than x
// find_by_order kth element
using ll=long long;
using ld=long double;
using pii=pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET(v,x) lower_bound(ALL(v),x)-v.begin()
const int maxn=2e5+5;
const ll INF=0x3f3f3f3f;
const ld PI=acos(-1.0l);
const ld eps=1e-6;
const ll INF64=4e18+1;
const int MOD=1e9+7;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<P.f<<' '<<P.s;
    return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
    REP(i,sz(V)) out<<V[i]<<((i!=sz(V)-1)?"\n":"");
    return out;
}
inline ll mult(ll a,ll b){
    return a*b%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
struct UFDSBP{
    vector<pii> par,rb;
    vector<int> rank1;
    void init(int n){
        rb.clear();
        REP(i,n) par.pb({i,0}),rank1.pb(1);
    }
    pii find(int u){
        if(par[u].f==u) return par[u];
        pii x=find(par[u].f);
        return {x.f,(x.s+par[u].s)%2};
    }
    bool merge(int a,int b){
        pii x=find(a),y=find(b);
        if(x.f==y.f) return x.s!=y.s;
        if(rank1[x.f]>rank1[y.f]) swap(x,y);
        par[x.f]={y.f,(x.s==y.s)};
        rank1[y.f]+=rank1[x.f];
        rb.pb({x.f,y.f});
        return true;
    }
    void roll(){
        pii x=rb.back();
        rb.pop_back();
        par[x.f]={x.f,0};
        rank1[x.s]-=rank1[x.f];
    }
}uf;
pii ed[maxn];
int mn[maxn];
void rec(int l,int r,int ql,int qr){
    if(l>r) return;
    int mid=(l+r)/2;
    int z=-1;
    for(int i=l;i<mid;i++) assert(uf.merge(ed[i].f,ed[i].s));
    for(int i=qr;i>=ql;i--){
        if(!uf.merge(ed[i].f,ed[i].s)){
            z=i;
            break;
        }
    }
    assert(z!=-1);
    mn[mid]=z;
    REP(i,qr-z+mid-l) uf.roll();
    for(int i=qr;i>z;i--) uf.merge(ed[i].f,ed[i].s);
    rec(l,mid-1,ql,z);
    REP(i,qr-z) uf.roll();
    for(int i=l;i<=mid;i++) uf.merge(ed[i].f,ed[i].s);
    rec(mid+1,r,max(z,mid+1),qr);
    REP(i,mid-l+1) uf.roll();
}
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n,m,q;
    cin>>n>>m>>q;
    uf.init(n);
    int ok=m;
    REP(i,m){
        cin>>ed[i].f>>ed[i].s;
        --ed[i].f,--ed[i].s;
        if(!uf.merge(ed[i].f,ed[i].s)){
            if(ok==m) ok=i;
        }
    }
    uf.init(n);
    if(ok==m){
        REP(i,q) cout<<"NO\n";
        return 0;
    }
    for(int i=ok;i<m;i++) mn[i]=INF;
    rec(0,ok-1,0,m-1);
    while(q--){
        int a,b;
        cin>>a>>b;
        --a,--b;
        if(b<mn[a]) cout<<"YES\n";
        else cout<<"NO\n";
    }
}   
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 53 ms 22328 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -