Rosetta Problems

All you need is Segment Tree.

https://hoj.hamako-ths.ed.jp/onlinejudge/problems/1663