Submission #258638

# Submission time Handle Problem Language Result Execution time Memory
258638 2020-08-06T09:48:57 Z Diuven Joker (BOI20_joker) C++14
100 / 100
616 ms 18136 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int MAX = 200010;
struct edge_t { int u, v; };
struct stat_t { int x, p, s, b; };
inline int _min(int a, int b){ return a<b ? a : b; }
inline int _max(int a, int b){ return a>b ? a : b; }


class bipuf {
    bool bip;
    int n, U[MAX*2], S[MAX*2];
    vector<stat_t> hist;
    int find(int x){
        return x==U[x] ? x : find(U[x]);
    }
    stat_t unite(int u, int v){
        u = find(u), v = find(v);
        stat_t bef = {0, 0, 0, bip};
        if(u==v) return bef;
        if(S[u]>S[v]) swap(u, v);
        bef = {u, U[u], S[v], bip};
        U[u] = v; S[v] += S[u];
        return bef;
    }
    void revert(stat_t st){
        bip = st.b;
        int v = st.x;
        if(v==0) return;
        S[U[v]] = st.s;
        U[v] = st.p;
    }
public:
    bipuf(int sz){
        bip = true;
        n = 2*sz+1;
        iota(U+1, U+n+1, 1);
        fill(S+1, S+n+1, 1);
    }
    void add_edge(edge_t e){
        int u = e.u, v = e.v;
        stat_t st1 = unite(u*2, v*2+1);
        stat_t st2 = unite(u*2+1, v*2);
        if(find(u*2) == find(u*2+1) || find(v*2) == find(v*2+1))
            bip = false;
        hist.push_back(st1);
        hist.push_back(st2);
    }
    void pop_edge(){
        stat_t st2 = hist.back(); hist.pop_back();
        stat_t st1 = hist.back(); hist.pop_back();
        revert(st2); revert(st1);
    }
    bool is_bip(){
        return bip;
    }
};

int n, m, q;
edge_t E[MAX];
int lim[MAX];
// lim[l] : using ([1,l] + [lim[l], m]) is bipartite

void solve(int s, int e, int l, int r, bipuf &UF){
    // UF set as [1, s) + (r, m]
    if(s>e) return;
    int mid = (s+e)/2, &pos = lim[mid];
    for(int i=_max(1, s); i<=mid; i++) UF.add_edge(E[i]);
    if(!UF.is_bip()) pos = m+2;
    // [1, mid] + (r, m]

    int bgn = _min(r, m), fin = _max(l, mid+1);
    for(int i=bgn; i>=fin; i--){
        UF.add_edge(E[i]);
        if(UF.is_bip()) pos=i;
    }
    // [1, mid] + [fin, m]
    for(int i=fin; i<=bgn; i++) UF.pop_edge();
    // [1, mid] + (r, m]

    solve(mid+1, e, pos, r, UF);

    for(int i=mid, ss=_max(1, s); i>=ss; i--) UF.pop_edge();
    // [1, s) + (r, m]
    int spl = _min(pos, bgn); 
    for(int i=bgn; i>spl; i--) UF.add_edge(E[i]);
    // [1, s) + (pos, m]

    solve(s, mid-1, l, pos, UF);
    for(int i=spl+1; i<=bgn; i++) UF.pop_edge();
    // [1, s) + (r, m]
}



int main(){
    ios::sync_with_stdio(0); cin.tie(0);

    cin>>n>>m>>q;

    for(int i=1; i<=m; i++){
        int u, v; cin>>u>>v;
        E[i] = {u, v};
    }
    fill(lim, lim+m+1, m+1);

    static bipuf UF(n);

    solve(0, m, 1, m+1, UF);

    for(int i=1; i<=q; i++){
        int l, r; cin>>l>>r;
        cout<<(lim[l-1] <= r+1 ? "NO" : "YES")<<'\n';
    }

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 4 ms 640 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 4 ms 640 KB Output is correct
35 Correct 4 ms 640 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 3 ms 640 KB Output is correct
38 Correct 3 ms 640 KB Output is correct
39 Correct 3 ms 640 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 3 ms 640 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 5 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 4 ms 640 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 3 ms 512 KB Output is correct
49 Correct 3 ms 640 KB Output is correct
50 Correct 3 ms 640 KB Output is correct
51 Correct 4 ms 512 KB Output is correct
52 Correct 4 ms 616 KB Output is correct
53 Correct 3 ms 640 KB Output is correct
54 Correct 3 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 305 ms 13764 KB Output is correct
4 Correct 375 ms 17000 KB Output is correct
5 Correct 414 ms 16852 KB Output is correct
6 Correct 415 ms 15316 KB Output is correct
7 Correct 454 ms 15444 KB Output is correct
8 Correct 467 ms 14440 KB Output is correct
9 Correct 513 ms 15208 KB Output is correct
10 Correct 584 ms 16872 KB Output is correct
11 Correct 429 ms 15272 KB Output is correct
12 Correct 485 ms 16596 KB Output is correct
13 Correct 500 ms 13908 KB Output is correct
14 Correct 484 ms 14696 KB Output is correct
15 Correct 616 ms 15976 KB Output is correct
16 Correct 608 ms 17108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 305 ms 13764 KB Output is correct
30 Correct 375 ms 17000 KB Output is correct
31 Correct 414 ms 16852 KB Output is correct
32 Correct 415 ms 15316 KB Output is correct
33 Correct 454 ms 15444 KB Output is correct
34 Correct 467 ms 14440 KB Output is correct
35 Correct 513 ms 15208 KB Output is correct
36 Correct 584 ms 16872 KB Output is correct
37 Correct 429 ms 15272 KB Output is correct
38 Correct 485 ms 16596 KB Output is correct
39 Correct 500 ms 13908 KB Output is correct
40 Correct 484 ms 14696 KB Output is correct
41 Correct 616 ms 15976 KB Output is correct
42 Correct 608 ms 17108 KB Output is correct
43 Correct 314 ms 12648 KB Output is correct
44 Correct 396 ms 14184 KB Output is correct
45 Correct 499 ms 14184 KB Output is correct
46 Correct 402 ms 12648 KB Output is correct
47 Correct 444 ms 12652 KB Output is correct
48 Correct 541 ms 12648 KB Output is correct
49 Correct 589 ms 14184 KB Output is correct
50 Correct 404 ms 12264 KB Output is correct
51 Correct 458 ms 13288 KB Output is correct
52 Correct 493 ms 14184 KB Output is correct
53 Correct 437 ms 11368 KB Output is correct
54 Correct 538 ms 12264 KB Output is correct
55 Correct 588 ms 13288 KB Output is correct
56 Correct 594 ms 14184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 4 ms 640 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 4 ms 640 KB Output is correct
35 Correct 4 ms 640 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 3 ms 640 KB Output is correct
38 Correct 3 ms 640 KB Output is correct
39 Correct 3 ms 640 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 3 ms 640 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 5 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 4 ms 640 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 3 ms 512 KB Output is correct
49 Correct 3 ms 640 KB Output is correct
50 Correct 3 ms 640 KB Output is correct
51 Correct 4 ms 512 KB Output is correct
52 Correct 4 ms 616 KB Output is correct
53 Correct 3 ms 640 KB Output is correct
54 Correct 3 ms 640 KB Output is correct
55 Correct 267 ms 12648 KB Output is correct
56 Correct 336 ms 16760 KB Output is correct
57 Correct 356 ms 16360 KB Output is correct
58 Correct 368 ms 14952 KB Output is correct
59 Correct 498 ms 14952 KB Output is correct
60 Correct 560 ms 16108 KB Output is correct
61 Correct 406 ms 14952 KB Output is correct
62 Correct 454 ms 16360 KB Output is correct
63 Correct 414 ms 13928 KB Output is correct
64 Correct 524 ms 15356 KB Output is correct
65 Correct 577 ms 16360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 512 KB Output is correct
30 Correct 3 ms 512 KB Output is correct
31 Correct 4 ms 640 KB Output is correct
32 Correct 3 ms 512 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 4 ms 640 KB Output is correct
35 Correct 4 ms 640 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 3 ms 640 KB Output is correct
38 Correct 3 ms 640 KB Output is correct
39 Correct 3 ms 640 KB Output is correct
40 Correct 3 ms 512 KB Output is correct
41 Correct 3 ms 512 KB Output is correct
42 Correct 3 ms 640 KB Output is correct
43 Correct 3 ms 512 KB Output is correct
44 Correct 5 ms 512 KB Output is correct
45 Correct 3 ms 512 KB Output is correct
46 Correct 4 ms 640 KB Output is correct
47 Correct 3 ms 512 KB Output is correct
48 Correct 3 ms 512 KB Output is correct
49 Correct 3 ms 640 KB Output is correct
50 Correct 3 ms 640 KB Output is correct
51 Correct 4 ms 512 KB Output is correct
52 Correct 4 ms 616 KB Output is correct
53 Correct 3 ms 640 KB Output is correct
54 Correct 3 ms 640 KB Output is correct
55 Correct 305 ms 13764 KB Output is correct
56 Correct 375 ms 17000 KB Output is correct
57 Correct 414 ms 16852 KB Output is correct
58 Correct 415 ms 15316 KB Output is correct
59 Correct 454 ms 15444 KB Output is correct
60 Correct 467 ms 14440 KB Output is correct
61 Correct 513 ms 15208 KB Output is correct
62 Correct 584 ms 16872 KB Output is correct
63 Correct 429 ms 15272 KB Output is correct
64 Correct 485 ms 16596 KB Output is correct
65 Correct 500 ms 13908 KB Output is correct
66 Correct 484 ms 14696 KB Output is correct
67 Correct 616 ms 15976 KB Output is correct
68 Correct 608 ms 17108 KB Output is correct
69 Correct 314 ms 12648 KB Output is correct
70 Correct 396 ms 14184 KB Output is correct
71 Correct 499 ms 14184 KB Output is correct
72 Correct 402 ms 12648 KB Output is correct
73 Correct 444 ms 12652 KB Output is correct
74 Correct 541 ms 12648 KB Output is correct
75 Correct 589 ms 14184 KB Output is correct
76 Correct 404 ms 12264 KB Output is correct
77 Correct 458 ms 13288 KB Output is correct
78 Correct 493 ms 14184 KB Output is correct
79 Correct 437 ms 11368 KB Output is correct
80 Correct 538 ms 12264 KB Output is correct
81 Correct 588 ms 13288 KB Output is correct
82 Correct 594 ms 14184 KB Output is correct
83 Correct 267 ms 12648 KB Output is correct
84 Correct 336 ms 16760 KB Output is correct
85 Correct 356 ms 16360 KB Output is correct
86 Correct 368 ms 14952 KB Output is correct
87 Correct 498 ms 14952 KB Output is correct
88 Correct 560 ms 16108 KB Output is correct
89 Correct 406 ms 14952 KB Output is correct
90 Correct 454 ms 16360 KB Output is correct
91 Correct 414 ms 13928 KB Output is correct
92 Correct 524 ms 15356 KB Output is correct
93 Correct 577 ms 16360 KB Output is correct
94 Correct 329 ms 16340 KB Output is correct
95 Correct 414 ms 17880 KB Output is correct
96 Correct 422 ms 17756 KB Output is correct
97 Correct 582 ms 16472 KB Output is correct
98 Correct 489 ms 16468 KB Output is correct
99 Correct 504 ms 15828 KB Output is correct
100 Correct 563 ms 18132 KB Output is correct
101 Correct 421 ms 16084 KB Output is correct
102 Correct 482 ms 17112 KB Output is correct
103 Correct 532 ms 18132 KB Output is correct
104 Correct 486 ms 15340 KB Output is correct
105 Correct 587 ms 16772 KB Output is correct
106 Correct 611 ms 17744 KB Output is correct
107 Correct 271 ms 18136 KB Output is correct
108 Correct 323 ms 16340 KB Output is correct
109 Correct 339 ms 16340 KB Output is correct
110 Correct 316 ms 16220 KB Output is correct
111 Correct 320 ms 16084 KB Output is correct
112 Correct 313 ms 16084 KB Output is correct
113 Correct 318 ms 16216 KB Output is correct
114 Correct 317 ms 16096 KB Output is correct
115 Correct 318 ms 16084 KB Output is correct
116 Correct 316 ms 16212 KB Output is correct