Kquery

hard
<a href="https://www.spoj.com/problems/KQUERY/">https://www.spoj.com/problems/KQUERY/</a>

Input Format

.

Output Format

.

Constraints

.

Notice

.

Example

Input
5
5 1 2 3 4
3
2 4 1
4 4 4
1 5 2 
Output
2
0
3 
Previous
Persistent Segment Tree

Related Questions