You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -229,6 +230,53 @@ pitem build (int * a, int n) {
229
230
230
231
Note: calling `upd_cnt(t)` is only necessary if you need the subtree sizes.
231
232
233
+
The approach above always provides a perfectly balanced tree, which is generally good for practical purposes, but at the cost of not preserving the priorities that were initially assigned to each node. Thus, this approach is not feasible to solve the following problem:
234
+
235
+
!!! example "[acmsguru - Cartesian Tree](https://codeforces.com/problemsets/acmsguru/problem/99999/155)"
236
+
Given a sequence of pairs $(x_i, y_i)$, construct a cartesian tree on them. All $x_i$ and all $y_i$ are unique.
237
+
238
+
Note that in this problem priorities are not random, hence just inserting vertices one by one could provide a quadratic solution.
239
+
240
+
One of possible solutions here is to find for each element the closest elements to the left and to the right which have a smaller priority than this element. Among these two elements, the one with the larger priority must be the parent of the current element.
241
+
242
+
This problem is solvable with a [minimum stack](./stack_queue_modification.md) modification in linear time:
Implicit treap is a simple modification of the regular treap which is a very powerful data structure. In fact, implicit treap can be considered as an array with the following procedures implemented (all in $O (\log N)$ in the online mode):
0 commit comments