Submission #1085956

# Submission time Handle Problem Language Result Execution time Memory
1085956 2024-09-09T07:37:37 Z not_amir Joker (BOI20_joker) C++14
100 / 100
165 ms 11092 KB
#include <bits/stdc++.h>
using namespace std;
 
#define pii pair<int, int>
#define pib pair<int, bool>
 
struct weightedDSU{
    vector<int> parent, weight, index;
    vector<bool> val;
    
    weightedDSU(int n) : parent(n), weight(n, -1), index(n), val(n) {
        for(int i = 0; i < n; i++){
            parent[i] = i;
            index[i] = rand();
        }
    }
    
    pib getRoot(int v, int w = 0){
        bool x = 0;
        while(weight[v] >= w){
            while(weight[parent[v]] >= weight[v]){
                val[v] = val[v] ^ val[parent[v]];
                parent[v] = parent[parent[v]];
            }
            x ^= val[v];
            v = parent[v];
        }
        return {v, x};
    }
    
    void addEdgeHelper(int u, int v, int w, bool x){
        while(u != v){
            pib tmp;
            tmp = getRoot(u, w);
            x ^= tmp.second;
            u = tmp.first;
            tmp = getRoot(v, w);
            x ^= tmp.second;
            v = tmp.first;
            if(index[u] < index[v])
                swap(u, v);
            int temp_parent = parent[v], temp_weight = weight[v];
            bool temp_val = val[v];
            parent[v] = u;
            weight[v] = w;
            val[v] = x;
            u = temp_parent;
            w = temp_weight;
            x = temp_val;
        }
    }
    
    int mainEdge(int u, int v){
        while(u != parent[v] && v != parent[u]){
            if(weight[u] > weight[v])
                u = parent[u];
            else
                v = parent[v];
        }
        if(u == parent[v])
            return v;
        else
            return u;
    }
    
    void deleteEdge(int u, int v, int w){
        getRoot(u);
        getRoot(v);
        int p = mainEdge(u, v);
        if(weight[p] == w){
            parent[p] = p;
            weight[p] = -1;
        }
    }
};
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, q;
    cin >> n >> m >> q;
    weightedDSU mst(n + 1);
    vector<pii> edges(m);
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        edges[i] = {u, v};
    }
    int curr = 0;
    vector<int> last(m + 1);
    for(int k = 0; k < 2 * m; k++){
        int i = k % m;
        int u = edges[i].first, v = edges[i].second;
        pib u1 = mst.getRoot(u), v1 = mst.getRoot(v);
        if(u1.first == v1.first){
            int p = mst.mainEdge(u, v);
            if(u1.second == v1.second){
                int e = mst.weight[p];
                for(; curr <= e; curr++)
                    mst.deleteEdge(edges[curr % m].first, edges[curr % m].second, curr);
            }
            else{
                mst.parent[p] = p;
                mst.weight[p] = -1;
            }
        }
        mst.addEdgeHelper(u, v, k, 1);
        if(k > m - 2)
            last[k - m + 1] = curr;
    }
    while(q--){
        int l, r;
        cin >> l >> r;
        if(r < last[l - 1])
            cout << "YES\n";
        else
            cout << "NO\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 404 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 404 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 528 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 464 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 1 ms 408 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 156 ms 8600 KB Output is correct
4 Correct 99 ms 9300 KB Output is correct
5 Correct 98 ms 9812 KB Output is correct
6 Correct 82 ms 8592 KB Output is correct
7 Correct 89 ms 8532 KB Output is correct
8 Correct 119 ms 7504 KB Output is correct
9 Correct 117 ms 8088 KB Output is correct
10 Correct 97 ms 9300 KB Output is correct
11 Correct 93 ms 8328 KB Output is correct
12 Correct 92 ms 9640 KB Output is correct
13 Correct 119 ms 7512 KB Output is correct
14 Correct 121 ms 7984 KB Output is correct
15 Correct 114 ms 9036 KB Output is correct
16 Correct 101 ms 9892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 404 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 156 ms 8600 KB Output is correct
30 Correct 99 ms 9300 KB Output is correct
31 Correct 98 ms 9812 KB Output is correct
32 Correct 82 ms 8592 KB Output is correct
33 Correct 89 ms 8532 KB Output is correct
34 Correct 119 ms 7504 KB Output is correct
35 Correct 117 ms 8088 KB Output is correct
36 Correct 97 ms 9300 KB Output is correct
37 Correct 93 ms 8328 KB Output is correct
38 Correct 92 ms 9640 KB Output is correct
39 Correct 119 ms 7512 KB Output is correct
40 Correct 121 ms 7984 KB Output is correct
41 Correct 114 ms 9036 KB Output is correct
42 Correct 101 ms 9892 KB Output is correct
43 Correct 157 ms 8792 KB Output is correct
44 Correct 100 ms 9636 KB Output is correct
45 Correct 92 ms 10068 KB Output is correct
46 Correct 86 ms 8844 KB Output is correct
47 Correct 92 ms 8960 KB Output is correct
48 Correct 117 ms 8528 KB Output is correct
49 Correct 100 ms 9808 KB Output is correct
50 Correct 97 ms 8464 KB Output is correct
51 Correct 90 ms 9444 KB Output is correct
52 Correct 100 ms 10068 KB Output is correct
53 Correct 121 ms 7628 KB Output is correct
54 Correct 117 ms 8532 KB Output is correct
55 Correct 112 ms 9448 KB Output is correct
56 Correct 104 ms 10032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 404 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 528 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 464 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 1 ms 408 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 2 ms 348 KB Output is correct
55 Correct 129 ms 6316 KB Output is correct
56 Correct 81 ms 7736 KB Output is correct
57 Correct 71 ms 7252 KB Output is correct
58 Correct 67 ms 6272 KB Output is correct
59 Correct 92 ms 6236 KB Output is correct
60 Correct 89 ms 7456 KB Output is correct
61 Correct 70 ms 6332 KB Output is correct
62 Correct 73 ms 7228 KB Output is correct
63 Correct 108 ms 5448 KB Output is correct
64 Correct 92 ms 6488 KB Output is correct
65 Correct 77 ms 7356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 404 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 528 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 464 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 2 ms 348 KB Output is correct
52 Correct 1 ms 408 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 2 ms 348 KB Output is correct
55 Correct 156 ms 8600 KB Output is correct
56 Correct 99 ms 9300 KB Output is correct
57 Correct 98 ms 9812 KB Output is correct
58 Correct 82 ms 8592 KB Output is correct
59 Correct 89 ms 8532 KB Output is correct
60 Correct 119 ms 7504 KB Output is correct
61 Correct 117 ms 8088 KB Output is correct
62 Correct 97 ms 9300 KB Output is correct
63 Correct 93 ms 8328 KB Output is correct
64 Correct 92 ms 9640 KB Output is correct
65 Correct 119 ms 7512 KB Output is correct
66 Correct 121 ms 7984 KB Output is correct
67 Correct 114 ms 9036 KB Output is correct
68 Correct 101 ms 9892 KB Output is correct
69 Correct 157 ms 8792 KB Output is correct
70 Correct 100 ms 9636 KB Output is correct
71 Correct 92 ms 10068 KB Output is correct
72 Correct 86 ms 8844 KB Output is correct
73 Correct 92 ms 8960 KB Output is correct
74 Correct 117 ms 8528 KB Output is correct
75 Correct 100 ms 9808 KB Output is correct
76 Correct 97 ms 8464 KB Output is correct
77 Correct 90 ms 9444 KB Output is correct
78 Correct 100 ms 10068 KB Output is correct
79 Correct 121 ms 7628 KB Output is correct
80 Correct 117 ms 8532 KB Output is correct
81 Correct 112 ms 9448 KB Output is correct
82 Correct 104 ms 10032 KB Output is correct
83 Correct 129 ms 6316 KB Output is correct
84 Correct 81 ms 7736 KB Output is correct
85 Correct 71 ms 7252 KB Output is correct
86 Correct 67 ms 6272 KB Output is correct
87 Correct 92 ms 6236 KB Output is correct
88 Correct 89 ms 7456 KB Output is correct
89 Correct 70 ms 6332 KB Output is correct
90 Correct 73 ms 7228 KB Output is correct
91 Correct 108 ms 5448 KB Output is correct
92 Correct 92 ms 6488 KB Output is correct
93 Correct 77 ms 7356 KB Output is correct
94 Correct 156 ms 9596 KB Output is correct
95 Correct 106 ms 10668 KB Output is correct
96 Correct 97 ms 10576 KB Output is correct
97 Correct 87 ms 9556 KB Output is correct
98 Correct 93 ms 9556 KB Output is correct
99 Correct 128 ms 9044 KB Output is correct
100 Correct 99 ms 10836 KB Output is correct
101 Correct 100 ms 9296 KB Output is correct
102 Correct 96 ms 10064 KB Output is correct
103 Correct 102 ms 10836 KB Output is correct
104 Correct 128 ms 8788 KB Output is correct
105 Correct 121 ms 9856 KB Output is correct
106 Correct 131 ms 10576 KB Output is correct
107 Correct 65 ms 11092 KB Output is correct
108 Correct 156 ms 9296 KB Output is correct
109 Correct 155 ms 9300 KB Output is correct
110 Correct 165 ms 9296 KB Output is correct
111 Correct 155 ms 9364 KB Output is correct
112 Correct 157 ms 9352 KB Output is correct
113 Correct 151 ms 9304 KB Output is correct
114 Correct 152 ms 9224 KB Output is correct
115 Correct 154 ms 9344 KB Output is correct
116 Correct 152 ms 9356 KB Output is correct