Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Hints: Star Map

All $x_i$ are distinct and all $y_i$ are distinct, so after sorting by $x$ the points form two monotone chains in $y$: think of an upper hull and lower hull as you sweep $x$ from left to right.
Answer to Hint 1: A triangle is harmonious if its three vertices lie on the boundary of some axis-aligned rectangle. If you have three points with increasing $x$ and the middle one is strictly above both neighbors (a local maximum in $y$), they often sit on three sides of a common axis-aligned rectangle — exactly what the upper-chain routine in model_sol.cpp detects.
Answer to Hint 2: Maintain a stack up of points for the upper chain. When the last two points on up together with the new point $p$ form a “mountain” (previous $<$ middle in $x$, middle highest in $y$, new on the right), pop the middle and record a triangle (prev, top, p).
Answer to Hint 3: Symmetrically maintain down for local minima in $y$ (middle strictly below neighbors). Each time the pattern matches, pop and emit a triangle.
Answer to Hint 4: Triangles built from disjoint $x$-intervals have disjoint interiors when produced by this stack peeling — the model prints all of them and uses each interior at most once.
Answer to Hint 5: Sort by $x$ once per test case; each point is pushed/popped $O(1)$ amortized — total $O(n \log n)$ time.