답안 #660223

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660223 2022-11-21T07:40:45 Z zaneyu Joker (BOI20_joker) C++14
100 / 100
288 ms 21332 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(),par.clear(),rank1.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){
            rb.pb({-1,-1});
            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();
        if(x.f!=-1){
            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+1+mid-l) uf.roll();
    if(l<mid){
        for(int i=qr;i>z;i--) assert(uf.merge(ed[i].f,ed[i].s));
        rec(l,mid-1,ql,z);
        REP(i,qr-z) uf.roll();
    }
    if(mid<r){
        for(int i=l;i<=mid;i++) assert(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+1;i<m;i++) mn[i]=INF;
    rec(0,ok,0,m-1);
    while(q--){
        int a,b;
        cin>>a>>b;
        --a,--b;
        if(b<mn[a]) cout<<"YES\n";
        else cout<<"NO\n";
    }
}   
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 272 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 272 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 472 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 420 KB Output is correct
33 Correct 2 ms 472 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 2 ms 472 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 476 KB Output is correct
44 Correct 2 ms 396 KB Output is correct
45 Correct 2 ms 464 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 472 KB Output is correct
49 Correct 3 ms 700 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 2 ms 468 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 168 ms 11964 KB Output is correct
4 Correct 63 ms 17784 KB Output is correct
5 Correct 173 ms 19756 KB Output is correct
6 Correct 141 ms 16020 KB Output is correct
7 Correct 136 ms 16120 KB Output is correct
8 Correct 170 ms 13660 KB Output is correct
9 Correct 189 ms 15432 KB Output is correct
10 Correct 230 ms 19640 KB Output is correct
11 Correct 166 ms 16116 KB Output is correct
12 Correct 191 ms 19736 KB Output is correct
13 Correct 166 ms 12764 KB Output is correct
14 Correct 163 ms 14144 KB Output is correct
15 Correct 201 ms 18784 KB Output is correct
16 Correct 225 ms 20100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 272 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 168 ms 11964 KB Output is correct
30 Correct 63 ms 17784 KB Output is correct
31 Correct 173 ms 19756 KB Output is correct
32 Correct 141 ms 16020 KB Output is correct
33 Correct 136 ms 16120 KB Output is correct
34 Correct 170 ms 13660 KB Output is correct
35 Correct 189 ms 15432 KB Output is correct
36 Correct 230 ms 19640 KB Output is correct
37 Correct 166 ms 16116 KB Output is correct
38 Correct 191 ms 19736 KB Output is correct
39 Correct 166 ms 12764 KB Output is correct
40 Correct 163 ms 14144 KB Output is correct
41 Correct 201 ms 18784 KB Output is correct
42 Correct 225 ms 20100 KB Output is correct
43 Correct 155 ms 16268 KB Output is correct
44 Correct 65 ms 17868 KB Output is correct
45 Correct 232 ms 20284 KB Output is correct
46 Correct 130 ms 16272 KB Output is correct
47 Correct 154 ms 16488 KB Output is correct
48 Correct 186 ms 15940 KB Output is correct
49 Correct 263 ms 20192 KB Output is correct
50 Correct 171 ms 15768 KB Output is correct
51 Correct 190 ms 19272 KB Output is correct
52 Correct 189 ms 20340 KB Output is correct
53 Correct 166 ms 13052 KB Output is correct
54 Correct 230 ms 15936 KB Output is correct
55 Correct 211 ms 19240 KB Output is correct
56 Correct 288 ms 20352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 272 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 472 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 420 KB Output is correct
33 Correct 2 ms 472 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 2 ms 472 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 476 KB Output is correct
44 Correct 2 ms 396 KB Output is correct
45 Correct 2 ms 464 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 472 KB Output is correct
49 Correct 3 ms 700 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 2 ms 468 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 124 ms 13604 KB Output is correct
56 Correct 61 ms 17048 KB Output is correct
57 Correct 177 ms 17468 KB Output is correct
58 Correct 124 ms 13680 KB Output is correct
59 Correct 180 ms 13620 KB Output is correct
60 Correct 213 ms 17084 KB Output is correct
61 Correct 169 ms 13680 KB Output is correct
62 Correct 208 ms 17388 KB Output is correct
63 Correct 148 ms 11372 KB Output is correct
64 Correct 230 ms 14092 KB Output is correct
65 Correct 216 ms 17492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 272 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 328 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 472 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 420 KB Output is correct
33 Correct 2 ms 472 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 2 ms 472 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 1 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 476 KB Output is correct
44 Correct 2 ms 396 KB Output is correct
45 Correct 2 ms 464 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 472 KB Output is correct
49 Correct 3 ms 700 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 2 ms 468 KB Output is correct
52 Correct 2 ms 468 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 168 ms 11964 KB Output is correct
56 Correct 63 ms 17784 KB Output is correct
57 Correct 173 ms 19756 KB Output is correct
58 Correct 141 ms 16020 KB Output is correct
59 Correct 136 ms 16120 KB Output is correct
60 Correct 170 ms 13660 KB Output is correct
61 Correct 189 ms 15432 KB Output is correct
62 Correct 230 ms 19640 KB Output is correct
63 Correct 166 ms 16116 KB Output is correct
64 Correct 191 ms 19736 KB Output is correct
65 Correct 166 ms 12764 KB Output is correct
66 Correct 163 ms 14144 KB Output is correct
67 Correct 201 ms 18784 KB Output is correct
68 Correct 225 ms 20100 KB Output is correct
69 Correct 155 ms 16268 KB Output is correct
70 Correct 65 ms 17868 KB Output is correct
71 Correct 232 ms 20284 KB Output is correct
72 Correct 130 ms 16272 KB Output is correct
73 Correct 154 ms 16488 KB Output is correct
74 Correct 186 ms 15940 KB Output is correct
75 Correct 263 ms 20192 KB Output is correct
76 Correct 171 ms 15768 KB Output is correct
77 Correct 190 ms 19272 KB Output is correct
78 Correct 189 ms 20340 KB Output is correct
79 Correct 166 ms 13052 KB Output is correct
80 Correct 230 ms 15936 KB Output is correct
81 Correct 211 ms 19240 KB Output is correct
82 Correct 288 ms 20352 KB Output is correct
83 Correct 124 ms 13604 KB Output is correct
84 Correct 61 ms 17048 KB Output is correct
85 Correct 177 ms 17468 KB Output is correct
86 Correct 124 ms 13680 KB Output is correct
87 Correct 180 ms 13620 KB Output is correct
88 Correct 213 ms 17084 KB Output is correct
89 Correct 169 ms 13680 KB Output is correct
90 Correct 208 ms 17388 KB Output is correct
91 Correct 148 ms 11372 KB Output is correct
92 Correct 230 ms 14092 KB Output is correct
93 Correct 216 ms 17492 KB Output is correct
94 Correct 168 ms 16908 KB Output is correct
95 Correct 284 ms 21040 KB Output is correct
96 Correct 195 ms 20752 KB Output is correct
97 Correct 144 ms 17028 KB Output is correct
98 Correct 187 ms 17132 KB Output is correct
99 Correct 197 ms 15076 KB Output is correct
100 Correct 257 ms 21200 KB Output is correct
101 Correct 175 ms 16600 KB Output is correct
102 Correct 214 ms 19868 KB Output is correct
103 Correct 217 ms 21260 KB Output is correct
104 Correct 175 ms 14708 KB Output is correct
105 Correct 208 ms 17416 KB Output is correct
106 Correct 258 ms 20760 KB Output is correct
107 Correct 148 ms 21332 KB Output is correct
108 Correct 156 ms 16808 KB Output is correct
109 Correct 167 ms 16804 KB Output is correct
110 Correct 154 ms 16736 KB Output is correct
111 Correct 162 ms 16704 KB Output is correct
112 Correct 164 ms 16820 KB Output is correct
113 Correct 152 ms 16764 KB Output is correct
114 Correct 153 ms 16808 KB Output is correct
115 Correct 151 ms 16760 KB Output is correct
116 Correct 161 ms 16684 KB Output is correct