Desperate Fire Survive

아직 제출이 없습니다시간 제한3초메모리 제한256 MB

문제

Rikka is running with her every cell to the hall where the contest will be held.

Well, EC Final is growing bigger and bigger... Thus more and more computers have been connected into the weak 2000W main wires. Heat is accumulating in every row.

When Rikka enters the hall, she finds LCR there rearranging the wires with the volunteers. However, the girl might not be able to do anything helpful but observing.

"Listen. We have no time to calculate parameters for the new circuit. Are you good at data structures? Help us, please..."

The circuitry is a sequence of nn nodes, where there are mm possible levels of nodes in total, numbered from 11 to mm. Since a kk-level node has a power limit twice of a (k1)(k-1)-level one, Rikka could merge two adjacent kk-level nodes into a (k+1)(k+1)-level one if k<mk < m. She can also remove any node at any time from the circuitry while the order of rest nodes remains.

The volunteers have qq queries in total. Each query contains a segment \[l,r]\[l,r] and an integer level kk. Rikka needs to count how many sub-segments of the assigned segment (i.e. a segment \[x,y]\[x, y] such that lxyrl\le x\le y\le r) can provide a kk-level node, which means it is possible to turn circuitry sequence \[x,y]\[x,y] into a single kk-level node by merging adjacent nodes at the same level and removing nodes, where these two types of operations can be performed multiple times in any order. Notice that the level must be exactly kk rather than higher or lower.

입력

The first line contains three integers n,m,q(1n,m,q2×105)n,m,q (1 \leq n,m,q \leq 2 \times 10^5), the length of the circuitry sequence, the maximal level and the number of queries, respectively.

The second line contains nn integers A_1,A_2,,A_n(1A_im)A\_1, A\_2, \dots, A\_n (1 \leq A\_i \leq m), the levels of nodes in order.

Each of the following qq lines contains three integers l,r,k(1lrn,1km)l,r,k (1 \leq l \leq r \leq n, 1 \leq k \leq m), describing a query.

Multiple integers in the same line are separated by spaces.

출력

Output qq lines; each contains one integer, the answer to that query.