Submission #877690

# Submission time Handle Problem Language Result Execution time Memory
877690 2023-11-23T12:49:06 Z bachhoangxuan Joker (BOI20_joker) C++17
100 / 100
194 ms 13924 KB
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/

#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define ld long double
#define pii pair<int,int>
#define piii pair<pii,int>
#define mpp make_pair
#define fi first
#define se second
const int mod=998244353;
const int maxn=200005;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=20;
const int maxa=1000000;
const int root=3;
const int base=101;

int n,m,q,lst[maxn];
pii p[maxn];

struct event{
    int pu,pv;
    bool cur;
};

namespace DSU{
    bool check=true;
    int par[maxn],d[maxn],sz[maxn];
    vector<event> E;
    void reset(){
        check=true;E.clear();
        for(int i=1;i<=n;i++) par[i]=i,d[i]=0,sz[i]=1;
    }
    pii findpar(int u){
        if(u!=par[u]){
            pii x=findpar(par[u]);
            return {x.fi,x.se^d[u]};
        }
        return {u,0};
    }

    void unions(int u,int v){
        auto [pu,du]=findpar(u);
        auto [pv,dv]=findpar(v);
        if(pu==pv){
            E.push_back({pu,pv,check});
            if(du==dv) check=false;
            return;
        }
        if(sz[pu]<sz[pv]) swap(pu,pv),swap(du,dv);
        E.push_back({pu,pv,check});
        par[pv]=pu;sz[pu]+=sz[pv];
        d[pv]^=du^dv^1;
    }
    void roll_back(){
        event e=E.back();
        E.pop_back();
        check=e.cur;
        int pu=e.pu,pv=e.pv;
        if(pu==pv) return;
        d[pv]=0;par[pv]=pv;
        sz[pu]-=sz[pv];
    }
}

void dnc(int l,int r,int optl,int optr){
    int mid=(l+r)>>1;
    for(int i=l;i<mid;i++) DSU::unions(p[i].fi,p[i].se);
    int opt=optr;
    while(DSU::check) DSU::unions(p[opt].fi,p[opt].se),opt--;
    lst[mid]=opt;
    for(int i=opt+1;i<=optr;i++) DSU::roll_back();
    DSU::unions(p[mid].fi,p[mid].se);
    if(mid<r) dnc(mid+1,r,opt,optr);
    for(int i=l;i<=mid;i++) DSU::roll_back();
    for(int i=optr;i>opt;i--) DSU::unions(p[i].fi,p[i].se);
    if(l<mid) dnc(l,mid-1,optl,opt);
    for(int i=opt+1;i<=optr;i++) DSU::roll_back();

}

void solve(){
    cin >> n >> m >> q;
    DSU::reset();
    for(int i=1;i<=m;i++){
        cin >> p[i].fi >> p[i].se;
        DSU::unions(p[i].fi,p[i].se);
    }
    if(DSU::check){
        for(int i=1;i<=q;i++) cout << "NO\n";
        return;
    }
    DSU::reset();
    dnc(1,m,1,m);
    for(int i=1;i<=q;i++){
        int l,r;cin >> l >> r;
        if(r<=lst[l]) cout << "YES\n";
        else cout << "NO\n";
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4560 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4564 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4564 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4560 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4564 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4564 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 2 ms 4444 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 2 ms 4444 KB Output is correct
35 Correct 2 ms 4444 KB Output is correct
36 Correct 1 ms 4440 KB Output is correct
37 Correct 2 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4440 KB Output is correct
44 Correct 2 ms 4696 KB Output is correct
45 Correct 2 ms 4576 KB Output is correct
46 Correct 2 ms 4444 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 ms 4444 KB Output is correct
50 Correct 2 ms 4584 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4444 KB Output is correct
54 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 114 ms 10436 KB Output is correct
4 Correct 40 ms 10448 KB Output is correct
5 Correct 96 ms 12388 KB Output is correct
6 Correct 123 ms 12216 KB Output is correct
7 Correct 126 ms 12340 KB Output is correct
8 Correct 139 ms 11708 KB Output is correct
9 Correct 136 ms 12160 KB Output is correct
10 Correct 178 ms 11744 KB Output is correct
11 Correct 134 ms 11964 KB Output is correct
12 Correct 146 ms 12344 KB Output is correct
13 Correct 141 ms 11964 KB Output is correct
14 Correct 136 ms 12124 KB Output is correct
15 Correct 166 ms 12224 KB Output is correct
16 Correct 175 ms 12324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4560 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4564 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4564 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 114 ms 10436 KB Output is correct
30 Correct 40 ms 10448 KB Output is correct
31 Correct 96 ms 12388 KB Output is correct
32 Correct 123 ms 12216 KB Output is correct
33 Correct 126 ms 12340 KB Output is correct
34 Correct 139 ms 11708 KB Output is correct
35 Correct 136 ms 12160 KB Output is correct
36 Correct 178 ms 11744 KB Output is correct
37 Correct 134 ms 11964 KB Output is correct
38 Correct 146 ms 12344 KB Output is correct
39 Correct 141 ms 11964 KB Output is correct
40 Correct 136 ms 12124 KB Output is correct
41 Correct 166 ms 12224 KB Output is correct
42 Correct 175 ms 12324 KB Output is correct
43 Correct 115 ms 12552 KB Output is correct
44 Correct 42 ms 10948 KB Output is correct
45 Correct 146 ms 12628 KB Output is correct
46 Correct 121 ms 12480 KB Output is correct
47 Correct 124 ms 13068 KB Output is correct
48 Correct 149 ms 12008 KB Output is correct
49 Correct 176 ms 12316 KB Output is correct
50 Correct 135 ms 12988 KB Output is correct
51 Correct 157 ms 12428 KB Output is correct
52 Correct 146 ms 12472 KB Output is correct
53 Correct 152 ms 12172 KB Output is correct
54 Correct 152 ms 12572 KB Output is correct
55 Correct 165 ms 12600 KB Output is correct
56 Correct 188 ms 12600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4560 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4564 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4564 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 2 ms 4444 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 2 ms 4444 KB Output is correct
35 Correct 2 ms 4444 KB Output is correct
36 Correct 1 ms 4440 KB Output is correct
37 Correct 2 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4440 KB Output is correct
44 Correct 2 ms 4696 KB Output is correct
45 Correct 2 ms 4576 KB Output is correct
46 Correct 2 ms 4444 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 ms 4444 KB Output is correct
50 Correct 2 ms 4584 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4444 KB Output is correct
54 Correct 2 ms 4444 KB Output is correct
55 Correct 85 ms 9420 KB Output is correct
56 Correct 37 ms 9644 KB Output is correct
57 Correct 69 ms 9920 KB Output is correct
58 Correct 101 ms 10960 KB Output is correct
59 Correct 133 ms 10444 KB Output is correct
60 Correct 160 ms 9932 KB Output is correct
61 Correct 116 ms 9936 KB Output is correct
62 Correct 129 ms 10180 KB Output is correct
63 Correct 103 ms 9868 KB Output is correct
64 Correct 141 ms 10020 KB Output is correct
65 Correct 154 ms 10704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4560 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4564 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4564 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4440 KB Output is correct
30 Correct 2 ms 4444 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 2 ms 4444 KB Output is correct
34 Correct 2 ms 4444 KB Output is correct
35 Correct 2 ms 4444 KB Output is correct
36 Correct 1 ms 4440 KB Output is correct
37 Correct 2 ms 4444 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 2 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 2 ms 4440 KB Output is correct
44 Correct 2 ms 4696 KB Output is correct
45 Correct 2 ms 4576 KB Output is correct
46 Correct 2 ms 4444 KB Output is correct
47 Correct 2 ms 4444 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 2 ms 4444 KB Output is correct
50 Correct 2 ms 4584 KB Output is correct
51 Correct 2 ms 4444 KB Output is correct
52 Correct 2 ms 4444 KB Output is correct
53 Correct 2 ms 4444 KB Output is correct
54 Correct 2 ms 4444 KB Output is correct
55 Correct 114 ms 10436 KB Output is correct
56 Correct 40 ms 10448 KB Output is correct
57 Correct 96 ms 12388 KB Output is correct
58 Correct 123 ms 12216 KB Output is correct
59 Correct 126 ms 12340 KB Output is correct
60 Correct 139 ms 11708 KB Output is correct
61 Correct 136 ms 12160 KB Output is correct
62 Correct 178 ms 11744 KB Output is correct
63 Correct 134 ms 11964 KB Output is correct
64 Correct 146 ms 12344 KB Output is correct
65 Correct 141 ms 11964 KB Output is correct
66 Correct 136 ms 12124 KB Output is correct
67 Correct 166 ms 12224 KB Output is correct
68 Correct 175 ms 12324 KB Output is correct
69 Correct 115 ms 12552 KB Output is correct
70 Correct 42 ms 10948 KB Output is correct
71 Correct 146 ms 12628 KB Output is correct
72 Correct 121 ms 12480 KB Output is correct
73 Correct 124 ms 13068 KB Output is correct
74 Correct 149 ms 12008 KB Output is correct
75 Correct 176 ms 12316 KB Output is correct
76 Correct 135 ms 12988 KB Output is correct
77 Correct 157 ms 12428 KB Output is correct
78 Correct 146 ms 12472 KB Output is correct
79 Correct 152 ms 12172 KB Output is correct
80 Correct 152 ms 12572 KB Output is correct
81 Correct 165 ms 12600 KB Output is correct
82 Correct 188 ms 12600 KB Output is correct
83 Correct 85 ms 9420 KB Output is correct
84 Correct 37 ms 9644 KB Output is correct
85 Correct 69 ms 9920 KB Output is correct
86 Correct 101 ms 10960 KB Output is correct
87 Correct 133 ms 10444 KB Output is correct
88 Correct 160 ms 9932 KB Output is correct
89 Correct 116 ms 9936 KB Output is correct
90 Correct 129 ms 10180 KB Output is correct
91 Correct 103 ms 9868 KB Output is correct
92 Correct 141 ms 10020 KB Output is correct
93 Correct 154 ms 10704 KB Output is correct
94 Correct 138 ms 13244 KB Output is correct
95 Correct 143 ms 13240 KB Output is correct
96 Correct 109 ms 13256 KB Output is correct
97 Correct 132 ms 13368 KB Output is correct
98 Correct 135 ms 13244 KB Output is correct
99 Correct 153 ms 13088 KB Output is correct
100 Correct 171 ms 13512 KB Output is correct
101 Correct 143 ms 13016 KB Output is correct
102 Correct 158 ms 13364 KB Output is correct
103 Correct 174 ms 13244 KB Output is correct
104 Correct 143 ms 12992 KB Output is correct
105 Correct 172 ms 13284 KB Output is correct
106 Correct 194 ms 13268 KB Output is correct
107 Correct 91 ms 13924 KB Output is correct
108 Correct 121 ms 12992 KB Output is correct
109 Correct 119 ms 12988 KB Output is correct
110 Correct 121 ms 13732 KB Output is correct
111 Correct 117 ms 12984 KB Output is correct
112 Correct 112 ms 13536 KB Output is correct
113 Correct 116 ms 13504 KB Output is correct
114 Correct 116 ms 13756 KB Output is correct
115 Correct 113 ms 12892 KB Output is correct
116 Correct 114 ms 12984 KB Output is correct