@@ -46,7 +46,8 @@ const int MAX_NODES_GRAPH = 1e5;
46
46
47
47
struct PersistentSegmentTree {
48
48
static const int MAX_NODES_TREE = 2e6 ;
49
- int left_child [MAX_NODES_TREE + 1 ], right_child [MAX_NODES_TREE + 1 ], node_value [MAX_NODES_TREE + 1 ];
49
+ int left_child [MAX_NODES_TREE + 1 ], right_child [MAX_NODES_TREE + 1 ],
50
+ node_value [MAX_NODES_TREE + 1 ];
50
51
int nxt = 1 ;
51
52
/*
52
53
Updates the tree at a given position by incrementing the frequency of the specific
@@ -58,12 +59,15 @@ struct PersistentSegmentTree {
58
59
int new_node = ++ nxt ; // Create a new node for the updated tree version
59
60
60
61
if (l == r ) {
61
- node_value [new_node ] = node_value [v ] + 1 ; // At leaf, increment the value at position 'pos'
62
+ node_value [new_node ] =
63
+ node_value [v ] + 1 ; // At leaf, increment the value at position 'pos'
62
64
return new_node ;
63
65
}
64
66
65
- left_child[new_node ] = left_child[v ]; // Copy left child from the previous version
66
- right_child[new_node ] = right_child[v ]; // Copy right child from the previous version
67
+ left_child[new_node ] =
68
+ left_child[v ]; // Copy left child from the previous version
69
+ right_child[new_node ] =
70
+ right_child[v ]; // Copy right child from the previous version
67
71
int m = (l + r) / 2;
68
72
69
73
// Update the left or right child based on the position
@@ -74,7 +78,8 @@ struct PersistentSegmentTree {
74
78
}
75
79
76
80
// Update the current node's value by combining the values of its children
77
- node_value[new_node ] = node_value[left_child [new_node ]] + node_value[right_child [new_node ]];
81
+ node_value[new_node ] =
82
+ node_value[left_child [new_node ]] + node_value[right_child [new_node ]];
78
83
return new_node;
79
84
}
80
85
@@ -86,12 +91,15 @@ struct PersistentSegmentTree {
86
91
int m = (l + r) / 2;
87
92
88
93
// Calculate the number of elements in the left child of the current range
89
- int leftSubtreeCount = node_value[left_child [a ]] + node_value[left_child [b ]] - node_value[left_child [anc ]] - node_value[left_child [pr ]];
94
+ int leftSubtreeCount = node_value[left_child [a ]] + node_value[left_child [b ]] -
95
+ node_value[left_child [anc ]] - node_value[left_child [pr ]];
90
96
91
97
if (leftSubtreeCount >= k) {
92
- return query(left_child[a ], left_child[b ], left_child[anc ], left_child[pr ], l, m, k);
98
+ return query(left_child[a ], left_child[b ], left_child[anc ], left_child[pr ],
99
+ l, m, k);
93
100
} else {
94
- return query(right_child[a ], right_child[b ], right_child[anc ], right_child[pr ], m + 1, r, k - leftSubtreeCount);
101
+ return query(right_child[a ], right_child[b ], right_child[anc ],
102
+ right_child[pr ], m + 1, r, k - leftSubtreeCount);
95
103
}
96
104
}
97
105
};
@@ -100,7 +108,8 @@ PersistentSegmentTree pst;
100
108
101
109
struct Graph {
102
110
int LOG;
103
- int roots[MAX_NODES_GRAPH + 1 ], tin[MAX_NODES_GRAPH + 1 ], tout[MAX_NODES_GRAPH + 1 ], val[MAX_NODES_GRAPH + 1 ];
111
+ int roots[MAX_NODES_GRAPH + 1 ], tin[MAX_NODES_GRAPH + 1 ], tout[MAX_NODES_GRAPH + 1 ],
112
+ val[MAX_NODES_GRAPH + 1 ];
104
113
vector<vector<int>> up;
105
114
vector<int> graph[MAX_NODES_GRAPH + 1 ];
106
115
0 commit comments