답안 #973151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973151 2024-05-01T14:42:59 Z the_coding_pooh Joker (BOI20_joker) C++14
100 / 100
986 ms 25160 KB
#include <bits/stdc++.h>
#define uwu return 0;

using namespace std;

#define fs first
#define sc second

const int SIZE = 2e5 + 5;

const int PERSIST = -1, IS_BIPARTITE = -2;

struct check_bipartite{
    int N, pl ;

    struct Disjoint_Set_Union{
        stack <pair<int, int>> rollback;

        int DSU[2 * SIZE];

        bool status = 1;

        inline void init(int n){
            for (int i = 0; i <= 2 * n;i++){
                DSU[i] = -1;
            }
            return;
        }

        inline int find_parent(int node){
            if(DSU[node] < 0)
                return node;

            int pa = find_parent(DSU[node]);
            rollback.push({node, DSU[node]});
    
            return DSU[node] = pa;
        }

        inline void merge(int a, int b){
            a = find_parent(a);
            b = find_parent(b);
    
            if(a == b)
                return;
    
            rollback.push({a, DSU[a]});
            rollback.push({b, DSU[b]});

            if(DSU[b] <= DSU[a])
                swap(a, b);

            DSU[a] += DSU[b];
            DSU[b] = a;
            return;
        }

        inline void checkpoint(){
            rollback.push({PERSIST, 0});
            return;
        }

        inline void roll(){
            while(rollback.top().fs != PERSIST){
                if(rollback.top().fs == IS_BIPARTITE)
                    status = rollback.top().sc;
                else{
                    DSU[rollback.top().fs] = rollback.top().sc;
                }
                rollback.pop();
            }
            rollback.pop();
            return;
        }
    } dsu;

    void add(int a, int b){
        dsu.merge(a, b + N), dsu.merge(b, a + N);
        if(dsu.find_parent(a) == dsu.find_parent(a + N) || dsu.find_parent(b) == dsu.find_parent(b + N)){
            dsu.rollback.push({IS_BIPARTITE, dsu.status});
            dsu.status = 0;
        }
    }
}black_box;

int lft[SIZE];

pair <int, int> edge[SIZE];

void solve(int nl, int nr, int pl, int pr){
    // cout << nl << ' ' << nr << ' ' << pl << ' ' << pr << '\n';
    int nm = (nl + nr) / 2, pm;
    
    black_box.dsu.checkpoint();
    
    for (int i = nr; i > nm; i--){
        black_box.add(edge[i].fs, edge[i].sc);
    }
    
    black_box.dsu.checkpoint();
    
    pm = pl - 1;
    
    while(black_box.dsu.status && pm <= min(nm, pr - 1)){
        pm++;
        black_box.add(edge[pm].fs, edge[pm].sc);
    }
    
    black_box.dsu.roll();
    
    lft[nm] = pm;
    black_box.add(edge[nm].fs, edge[nm].sc);

    // cout << nm << ' ' << pm << '\n';

    if(pm > 0 && nl != nm)
        solve(nl, nm - 1, pl, pm);
    
    black_box.dsu.roll(), black_box.dsu.checkpoint();

    for (int i = pl; i < pm; i++){
        black_box.add(edge[i].fs, edge[i].sc);
    }
    
    if(nm != nr)
        solve(nm + 1, nr, max(pm, 1), pr);
    
    black_box.dsu.roll();
    return;
}

int main(){
    int N, M, Q;
    
    cin >> N >> M >> Q;
    
    black_box.N = N;
    black_box.dsu.init(N);
    
    for (int i = 1; i <= M;i++){
        cin >> edge[i].fs >> edge[i].sc;
    }

    solve(1, M, 1, M + 1);
    /*
    for (int i = 1; i <= M;i++){
        cout << i << ' ' << lft[i] << '\n';
    }
    */
    for (int l, r; Q--;){
        cin >> l >> r;
        lft[r] < l ? cout << "YES\n" : cout << "NO\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2496 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2500 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2496 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2496 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2500 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2496 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 6 ms 2552 KB Output is correct
30 Correct 6 ms 2664 KB Output is correct
31 Correct 6 ms 2392 KB Output is correct
32 Correct 6 ms 2396 KB Output is correct
33 Correct 5 ms 2628 KB Output is correct
34 Correct 6 ms 2652 KB Output is correct
35 Correct 6 ms 2516 KB Output is correct
36 Correct 6 ms 2652 KB Output is correct
37 Correct 9 ms 2652 KB Output is correct
38 Correct 8 ms 2652 KB Output is correct
39 Correct 6 ms 2652 KB Output is correct
40 Correct 6 ms 2676 KB Output is correct
41 Correct 6 ms 2652 KB Output is correct
42 Correct 5 ms 2684 KB Output is correct
43 Correct 5 ms 2652 KB Output is correct
44 Correct 6 ms 2636 KB Output is correct
45 Correct 6 ms 2648 KB Output is correct
46 Correct 6 ms 2652 KB Output is correct
47 Correct 6 ms 2648 KB Output is correct
48 Correct 6 ms 2648 KB Output is correct
49 Correct 7 ms 2652 KB Output is correct
50 Correct 7 ms 2676 KB Output is correct
51 Correct 6 ms 2652 KB Output is correct
52 Correct 6 ms 2652 KB Output is correct
53 Correct 6 ms 2652 KB Output is correct
54 Correct 7 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 706 ms 17232 KB Output is correct
4 Correct 955 ms 24604 KB Output is correct
5 Correct 531 ms 23108 KB Output is correct
6 Correct 573 ms 17380 KB Output is correct
7 Correct 637 ms 17764 KB Output is correct
8 Correct 586 ms 16312 KB Output is correct
9 Correct 652 ms 17252 KB Output is correct
10 Correct 756 ms 17644 KB Output is correct
11 Correct 656 ms 17124 KB Output is correct
12 Correct 678 ms 17120 KB Output is correct
13 Correct 570 ms 15080 KB Output is correct
14 Correct 626 ms 16428 KB Output is correct
15 Correct 666 ms 17696 KB Output is correct
16 Correct 813 ms 17888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2496 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2500 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2496 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 706 ms 17232 KB Output is correct
30 Correct 955 ms 24604 KB Output is correct
31 Correct 531 ms 23108 KB Output is correct
32 Correct 573 ms 17380 KB Output is correct
33 Correct 637 ms 17764 KB Output is correct
34 Correct 586 ms 16312 KB Output is correct
35 Correct 652 ms 17252 KB Output is correct
36 Correct 756 ms 17644 KB Output is correct
37 Correct 656 ms 17124 KB Output is correct
38 Correct 678 ms 17120 KB Output is correct
39 Correct 570 ms 15080 KB Output is correct
40 Correct 626 ms 16428 KB Output is correct
41 Correct 666 ms 17696 KB Output is correct
42 Correct 813 ms 17888 KB Output is correct
43 Correct 691 ms 17652 KB Output is correct
44 Correct 986 ms 25160 KB Output is correct
45 Correct 698 ms 23324 KB Output is correct
46 Correct 634 ms 17384 KB Output is correct
47 Correct 620 ms 17632 KB Output is correct
48 Correct 658 ms 17248 KB Output is correct
49 Correct 754 ms 17888 KB Output is correct
50 Correct 641 ms 16356 KB Output is correct
51 Correct 678 ms 17048 KB Output is correct
52 Correct 684 ms 17232 KB Output is correct
53 Correct 527 ms 15060 KB Output is correct
54 Correct 646 ms 16972 KB Output is correct
55 Correct 696 ms 17696 KB Output is correct
56 Correct 738 ms 17912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2496 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2500 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2496 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 6 ms 2552 KB Output is correct
30 Correct 6 ms 2664 KB Output is correct
31 Correct 6 ms 2392 KB Output is correct
32 Correct 6 ms 2396 KB Output is correct
33 Correct 5 ms 2628 KB Output is correct
34 Correct 6 ms 2652 KB Output is correct
35 Correct 6 ms 2516 KB Output is correct
36 Correct 6 ms 2652 KB Output is correct
37 Correct 9 ms 2652 KB Output is correct
38 Correct 8 ms 2652 KB Output is correct
39 Correct 6 ms 2652 KB Output is correct
40 Correct 6 ms 2676 KB Output is correct
41 Correct 6 ms 2652 KB Output is correct
42 Correct 5 ms 2684 KB Output is correct
43 Correct 5 ms 2652 KB Output is correct
44 Correct 6 ms 2636 KB Output is correct
45 Correct 6 ms 2648 KB Output is correct
46 Correct 6 ms 2652 KB Output is correct
47 Correct 6 ms 2648 KB Output is correct
48 Correct 6 ms 2648 KB Output is correct
49 Correct 7 ms 2652 KB Output is correct
50 Correct 7 ms 2676 KB Output is correct
51 Correct 6 ms 2652 KB Output is correct
52 Correct 6 ms 2652 KB Output is correct
53 Correct 6 ms 2652 KB Output is correct
54 Correct 7 ms 2648 KB Output is correct
55 Correct 383 ms 17376 KB Output is correct
56 Correct 657 ms 23148 KB Output is correct
57 Correct 222 ms 21440 KB Output is correct
58 Correct 293 ms 17124 KB Output is correct
59 Correct 357 ms 17124 KB Output is correct
60 Correct 428 ms 17592 KB Output is correct
61 Correct 367 ms 16980 KB Output is correct
62 Correct 398 ms 17156 KB Output is correct
63 Correct 261 ms 15584 KB Output is correct
64 Correct 371 ms 17664 KB Output is correct
65 Correct 437 ms 17636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2496 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2500 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2496 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 6 ms 2552 KB Output is correct
30 Correct 6 ms 2664 KB Output is correct
31 Correct 6 ms 2392 KB Output is correct
32 Correct 6 ms 2396 KB Output is correct
33 Correct 5 ms 2628 KB Output is correct
34 Correct 6 ms 2652 KB Output is correct
35 Correct 6 ms 2516 KB Output is correct
36 Correct 6 ms 2652 KB Output is correct
37 Correct 9 ms 2652 KB Output is correct
38 Correct 8 ms 2652 KB Output is correct
39 Correct 6 ms 2652 KB Output is correct
40 Correct 6 ms 2676 KB Output is correct
41 Correct 6 ms 2652 KB Output is correct
42 Correct 5 ms 2684 KB Output is correct
43 Correct 5 ms 2652 KB Output is correct
44 Correct 6 ms 2636 KB Output is correct
45 Correct 6 ms 2648 KB Output is correct
46 Correct 6 ms 2652 KB Output is correct
47 Correct 6 ms 2648 KB Output is correct
48 Correct 6 ms 2648 KB Output is correct
49 Correct 7 ms 2652 KB Output is correct
50 Correct 7 ms 2676 KB Output is correct
51 Correct 6 ms 2652 KB Output is correct
52 Correct 6 ms 2652 KB Output is correct
53 Correct 6 ms 2652 KB Output is correct
54 Correct 7 ms 2648 KB Output is correct
55 Correct 706 ms 17232 KB Output is correct
56 Correct 955 ms 24604 KB Output is correct
57 Correct 531 ms 23108 KB Output is correct
58 Correct 573 ms 17380 KB Output is correct
59 Correct 637 ms 17764 KB Output is correct
60 Correct 586 ms 16312 KB Output is correct
61 Correct 652 ms 17252 KB Output is correct
62 Correct 756 ms 17644 KB Output is correct
63 Correct 656 ms 17124 KB Output is correct
64 Correct 678 ms 17120 KB Output is correct
65 Correct 570 ms 15080 KB Output is correct
66 Correct 626 ms 16428 KB Output is correct
67 Correct 666 ms 17696 KB Output is correct
68 Correct 813 ms 17888 KB Output is correct
69 Correct 691 ms 17652 KB Output is correct
70 Correct 986 ms 25160 KB Output is correct
71 Correct 698 ms 23324 KB Output is correct
72 Correct 634 ms 17384 KB Output is correct
73 Correct 620 ms 17632 KB Output is correct
74 Correct 658 ms 17248 KB Output is correct
75 Correct 754 ms 17888 KB Output is correct
76 Correct 641 ms 16356 KB Output is correct
77 Correct 678 ms 17048 KB Output is correct
78 Correct 684 ms 17232 KB Output is correct
79 Correct 527 ms 15060 KB Output is correct
80 Correct 646 ms 16972 KB Output is correct
81 Correct 696 ms 17696 KB Output is correct
82 Correct 738 ms 17912 KB Output is correct
83 Correct 383 ms 17376 KB Output is correct
84 Correct 657 ms 23148 KB Output is correct
85 Correct 222 ms 21440 KB Output is correct
86 Correct 293 ms 17124 KB Output is correct
87 Correct 357 ms 17124 KB Output is correct
88 Correct 428 ms 17592 KB Output is correct
89 Correct 367 ms 16980 KB Output is correct
90 Correct 398 ms 17156 KB Output is correct
91 Correct 261 ms 15584 KB Output is correct
92 Correct 371 ms 17664 KB Output is correct
93 Correct 437 ms 17636 KB Output is correct
94 Correct 700 ms 17632 KB Output is correct
95 Correct 862 ms 23584 KB Output is correct
96 Correct 541 ms 24672 KB Output is correct
97 Correct 616 ms 17380 KB Output is correct
98 Correct 646 ms 17504 KB Output is correct
99 Correct 613 ms 16712 KB Output is correct
100 Correct 688 ms 17896 KB Output is correct
101 Correct 671 ms 16756 KB Output is correct
102 Correct 698 ms 17024 KB Output is correct
103 Correct 729 ms 17276 KB Output is correct
104 Correct 609 ms 16012 KB Output is correct
105 Correct 704 ms 17640 KB Output is correct
106 Correct 746 ms 17884 KB Output is correct
107 Correct 626 ms 23204 KB Output is correct
108 Correct 699 ms 17636 KB Output is correct
109 Correct 701 ms 17632 KB Output is correct
110 Correct 704 ms 17508 KB Output is correct
111 Correct 698 ms 17512 KB Output is correct
112 Correct 742 ms 17632 KB Output is correct
113 Correct 694 ms 17636 KB Output is correct
114 Correct 715 ms 17520 KB Output is correct
115 Correct 734 ms 17636 KB Output is correct
116 Correct 697 ms 17636 KB Output is correct