답안 #973152

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973152 2024-05-01T14:45:44 Z the_coding_pooh Joker (BOI20_joker) C++14
100 / 100
985 ms 21348 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;
 
    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 l, r; Q--;){
        cin >> l >> r;
        lft[r] < l ? cout << "YES\n" : cout << "NO\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2392 KB Output is correct
2 Correct 2 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 1 ms 2648 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 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 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 2396 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 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 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 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2392 KB Output is correct
2 Correct 2 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 1 ms 2648 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 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 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 2396 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 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 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 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 5 ms 2396 KB Output is correct
30 Correct 6 ms 2516 KB Output is correct
31 Correct 6 ms 2396 KB Output is correct
32 Correct 5 ms 2392 KB Output is correct
33 Correct 6 ms 2396 KB Output is correct
34 Correct 7 ms 2648 KB Output is correct
35 Correct 7 ms 2524 KB Output is correct
36 Correct 7 ms 2396 KB Output is correct
37 Correct 7 ms 2652 KB Output is correct
38 Correct 8 ms 2648 KB Output is correct
39 Correct 6 ms 2904 KB Output is correct
40 Correct 5 ms 2652 KB Output is correct
41 Correct 5 ms 2644 KB Output is correct
42 Correct 5 ms 2648 KB Output is correct
43 Correct 9 ms 2592 KB Output is correct
44 Correct 6 ms 2652 KB Output is correct
45 Correct 6 ms 2652 KB Output is correct
46 Correct 6 ms 2420 KB Output is correct
47 Correct 6 ms 2396 KB Output is correct
48 Correct 6 ms 2392 KB Output is correct
49 Correct 6 ms 2396 KB Output is correct
50 Correct 6 ms 2396 KB Output is correct
51 Correct 5 ms 2396 KB Output is correct
52 Correct 6 ms 2396 KB Output is correct
53 Correct 6 ms 2396 KB Output is correct
54 Correct 6 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2392 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 679 ms 15088 KB Output is correct
4 Correct 948 ms 21348 KB Output is correct
5 Correct 535 ms 19368 KB Output is correct
6 Correct 595 ms 14832 KB Output is correct
7 Correct 631 ms 14816 KB Output is correct
8 Correct 586 ms 14048 KB Output is correct
9 Correct 640 ms 14820 KB Output is correct
10 Correct 779 ms 15332 KB Output is correct
11 Correct 709 ms 14604 KB Output is correct
12 Correct 671 ms 14304 KB Output is correct
13 Correct 531 ms 12668 KB Output is correct
14 Correct 614 ms 14044 KB Output is correct
15 Correct 675 ms 15144 KB Output is correct
16 Correct 740 ms 15112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2392 KB Output is correct
2 Correct 2 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 1 ms 2648 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 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 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 2396 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 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 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 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 679 ms 15088 KB Output is correct
30 Correct 948 ms 21348 KB Output is correct
31 Correct 535 ms 19368 KB Output is correct
32 Correct 595 ms 14832 KB Output is correct
33 Correct 631 ms 14816 KB Output is correct
34 Correct 586 ms 14048 KB Output is correct
35 Correct 640 ms 14820 KB Output is correct
36 Correct 779 ms 15332 KB Output is correct
37 Correct 709 ms 14604 KB Output is correct
38 Correct 671 ms 14304 KB Output is correct
39 Correct 531 ms 12668 KB Output is correct
40 Correct 614 ms 14044 KB Output is correct
41 Correct 675 ms 15144 KB Output is correct
42 Correct 740 ms 15112 KB Output is correct
43 Correct 702 ms 15084 KB Output is correct
44 Correct 985 ms 21152 KB Output is correct
45 Correct 733 ms 20516 KB Output is correct
46 Correct 604 ms 14836 KB Output is correct
47 Correct 632 ms 14836 KB Output is correct
48 Correct 663 ms 14832 KB Output is correct
49 Correct 764 ms 15072 KB Output is correct
50 Correct 635 ms 13912 KB Output is correct
51 Correct 654 ms 14304 KB Output is correct
52 Correct 663 ms 14584 KB Output is correct
53 Correct 585 ms 12672 KB Output is correct
54 Correct 644 ms 14308 KB Output is correct
55 Correct 710 ms 15204 KB Output is correct
56 Correct 792 ms 15092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2392 KB Output is correct
2 Correct 2 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 1 ms 2648 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 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 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 2396 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 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 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 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 5 ms 2396 KB Output is correct
30 Correct 6 ms 2516 KB Output is correct
31 Correct 6 ms 2396 KB Output is correct
32 Correct 5 ms 2392 KB Output is correct
33 Correct 6 ms 2396 KB Output is correct
34 Correct 7 ms 2648 KB Output is correct
35 Correct 7 ms 2524 KB Output is correct
36 Correct 7 ms 2396 KB Output is correct
37 Correct 7 ms 2652 KB Output is correct
38 Correct 8 ms 2648 KB Output is correct
39 Correct 6 ms 2904 KB Output is correct
40 Correct 5 ms 2652 KB Output is correct
41 Correct 5 ms 2644 KB Output is correct
42 Correct 5 ms 2648 KB Output is correct
43 Correct 9 ms 2592 KB Output is correct
44 Correct 6 ms 2652 KB Output is correct
45 Correct 6 ms 2652 KB Output is correct
46 Correct 6 ms 2420 KB Output is correct
47 Correct 6 ms 2396 KB Output is correct
48 Correct 6 ms 2392 KB Output is correct
49 Correct 6 ms 2396 KB Output is correct
50 Correct 6 ms 2396 KB Output is correct
51 Correct 5 ms 2396 KB Output is correct
52 Correct 6 ms 2396 KB Output is correct
53 Correct 6 ms 2396 KB Output is correct
54 Correct 6 ms 2396 KB Output is correct
55 Correct 384 ms 15084 KB Output is correct
56 Correct 662 ms 20532 KB Output is correct
57 Correct 227 ms 18912 KB Output is correct
58 Correct 286 ms 14884 KB Output is correct
59 Correct 384 ms 14832 KB Output is correct
60 Correct 427 ms 15004 KB Output is correct
61 Correct 350 ms 14588 KB Output is correct
62 Correct 410 ms 14436 KB Output is correct
63 Correct 264 ms 13340 KB Output is correct
64 Correct 373 ms 15076 KB Output is correct
65 Correct 461 ms 15220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2392 KB Output is correct
2 Correct 2 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 1 ms 2648 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 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 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 2396 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 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 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 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 5 ms 2396 KB Output is correct
30 Correct 6 ms 2516 KB Output is correct
31 Correct 6 ms 2396 KB Output is correct
32 Correct 5 ms 2392 KB Output is correct
33 Correct 6 ms 2396 KB Output is correct
34 Correct 7 ms 2648 KB Output is correct
35 Correct 7 ms 2524 KB Output is correct
36 Correct 7 ms 2396 KB Output is correct
37 Correct 7 ms 2652 KB Output is correct
38 Correct 8 ms 2648 KB Output is correct
39 Correct 6 ms 2904 KB Output is correct
40 Correct 5 ms 2652 KB Output is correct
41 Correct 5 ms 2644 KB Output is correct
42 Correct 5 ms 2648 KB Output is correct
43 Correct 9 ms 2592 KB Output is correct
44 Correct 6 ms 2652 KB Output is correct
45 Correct 6 ms 2652 KB Output is correct
46 Correct 6 ms 2420 KB Output is correct
47 Correct 6 ms 2396 KB Output is correct
48 Correct 6 ms 2392 KB Output is correct
49 Correct 6 ms 2396 KB Output is correct
50 Correct 6 ms 2396 KB Output is correct
51 Correct 5 ms 2396 KB Output is correct
52 Correct 6 ms 2396 KB Output is correct
53 Correct 6 ms 2396 KB Output is correct
54 Correct 6 ms 2396 KB Output is correct
55 Correct 679 ms 15088 KB Output is correct
56 Correct 948 ms 21348 KB Output is correct
57 Correct 535 ms 19368 KB Output is correct
58 Correct 595 ms 14832 KB Output is correct
59 Correct 631 ms 14816 KB Output is correct
60 Correct 586 ms 14048 KB Output is correct
61 Correct 640 ms 14820 KB Output is correct
62 Correct 779 ms 15332 KB Output is correct
63 Correct 709 ms 14604 KB Output is correct
64 Correct 671 ms 14304 KB Output is correct
65 Correct 531 ms 12668 KB Output is correct
66 Correct 614 ms 14044 KB Output is correct
67 Correct 675 ms 15144 KB Output is correct
68 Correct 740 ms 15112 KB Output is correct
69 Correct 702 ms 15084 KB Output is correct
70 Correct 985 ms 21152 KB Output is correct
71 Correct 733 ms 20516 KB Output is correct
72 Correct 604 ms 14836 KB Output is correct
73 Correct 632 ms 14836 KB Output is correct
74 Correct 663 ms 14832 KB Output is correct
75 Correct 764 ms 15072 KB Output is correct
76 Correct 635 ms 13912 KB Output is correct
77 Correct 654 ms 14304 KB Output is correct
78 Correct 663 ms 14584 KB Output is correct
79 Correct 585 ms 12672 KB Output is correct
80 Correct 644 ms 14308 KB Output is correct
81 Correct 710 ms 15204 KB Output is correct
82 Correct 792 ms 15092 KB Output is correct
83 Correct 384 ms 15084 KB Output is correct
84 Correct 662 ms 20532 KB Output is correct
85 Correct 227 ms 18912 KB Output is correct
86 Correct 286 ms 14884 KB Output is correct
87 Correct 384 ms 14832 KB Output is correct
88 Correct 427 ms 15004 KB Output is correct
89 Correct 350 ms 14588 KB Output is correct
90 Correct 410 ms 14436 KB Output is correct
91 Correct 264 ms 13340 KB Output is correct
92 Correct 373 ms 15076 KB Output is correct
93 Correct 461 ms 15220 KB Output is correct
94 Correct 706 ms 15084 KB Output is correct
95 Correct 842 ms 20604 KB Output is correct
96 Correct 546 ms 19684 KB Output is correct
97 Correct 609 ms 14816 KB Output is correct
98 Correct 642 ms 14984 KB Output is correct
99 Correct 638 ms 13852 KB Output is correct
100 Correct 717 ms 15332 KB Output is correct
101 Correct 674 ms 13904 KB Output is correct
102 Correct 709 ms 14400 KB Output is correct
103 Correct 732 ms 14548 KB Output is correct
104 Correct 613 ms 13280 KB Output is correct
105 Correct 701 ms 15072 KB Output is correct
106 Correct 754 ms 15076 KB Output is correct
107 Correct 627 ms 17820 KB Output is correct
108 Correct 759 ms 15088 KB Output is correct
109 Correct 696 ms 15076 KB Output is correct
110 Correct 722 ms 15072 KB Output is correct
111 Correct 709 ms 15072 KB Output is correct
112 Correct 700 ms 15072 KB Output is correct
113 Correct 720 ms 15072 KB Output is correct
114 Correct 705 ms 15104 KB Output is correct
115 Correct 718 ms 15104 KB Output is correct
116 Correct 706 ms 15332 KB Output is correct