Skip to content

Commit f8279fd

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 81defd9 commit f8279fd

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

solutions/advanced/spoj-cot.mdx

+18-9
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ const int MAX_NODES_GRAPH = 1e5;
4646

4747
struct PersistentSegmentTree {
4848
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];
5051
int nxt = 1;
5152
/*
5253
Updates the tree at a given position by incrementing the frequency of the specific
@@ -58,12 +59,15 @@ struct PersistentSegmentTree {
5859
int new_node = ++nxt; // Create a new node for the updated tree version
5960

6061
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'
6264
return new_node;
6365
}
6466

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
6771
int m = (l + r) / 2;
6872

6973
// Update the left or right child based on the position
@@ -74,7 +78,8 @@ struct PersistentSegmentTree {
7478
}
7579

7680
// 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]];
7883
return new_node;
7984
}
8085

@@ -86,12 +91,15 @@ struct PersistentSegmentTree {
8691
int m = (l + r) / 2;
8792

8893
// 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]];
9096

9197
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);
93100
} 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);
95103
}
96104
}
97105
};
@@ -100,7 +108,8 @@ PersistentSegmentTree pst;
100108

101109
struct Graph {
102110
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];
104113
vector<vector<int>> up;
105114
vector<int> graph[MAX_NODES_GRAPH + 1];
106115

0 commit comments

Comments
 (0)