Editorial

Solution Walkthrough

RSQ Queries

Editorial

There are many solutions to this problem. One of them is using segment tree.

Author's Solution

GNU C++23