PSHTRG [Unofficial Editorial] (Pishty and Triangles) MARCH LONG

My solution

I used iterative segment tree as described here. Very efficient and easy to implement/debug/personalise.

1 Like

I need some reputation pointsā€¦ Please upvote this comment /\

Official editorial is outā€¦ and hereā€™s my solution which breaks the range in blocks of 60 and solves the problem.

can u explain the get function in your solution?

can u please explain the approach?

Will surely try to do that :slight_smile:

@beginner_1111 if you follow the link I provided above, you can find a function named query() in the beginning of the blog. It gives the result of a segment tree range query for range [l,r). Similar implementation is get() which solves for range [l,r]. Notice that the whole blog follows 0-indexing.