CSES - Aalto Competitive Programming 2024 - wk4 - Mon - Targeted advertising
  • Time limit: 1.50 s
  • Memory limit: 512 MB

Maija works at a software company that sells its customers' information to other companies on demand. The company's database contains information about the customers' interests and is sorted by their age, from youngest to oldest. The database is flooded with the following type of queries: How many people between the ages [a,b][a, b] are interested in thing cc? It can no longer keep up with the queries and Maija is tasked to write some specialized software to solve this issue.

The database contains nn people numbered 1,2,,n1,2,\dots,n and kk things people are interested in. The ii-th youngest person is interested in thing aia_i. There are also qq pre-processed queries of the form: l r xl\ r\ x - how many people between the ll-th youngest and rr-th youngest (inclusive) are interested in thing x?

Input

The first line contains three integers nn,kk, and qq. The second line contains nn integers a1,a2,,ana_1,\,a_2,\dots,\,a_n. The 𝑖𝑖-th of the next qq lines contains three integers lil_i, r𝑖r_𝑖, and xix_i.

Output

Print the answers to the queries, each on their own line.

Constraints

  • 1n,k,q1051 \leq n, k, q \leq 10^5
  • 1aik1 \leq a_i \leq k
  • 1lrn1 \leq l \leq r \leq n
  • 1xk1 \leq x \leq k

Example 1

Input:

5 5 5
3 1 5 5 4
1 3 1
2 4 4
3 4 5
1 5 3
3 4 1

Output:

1
0
2
1
0

Example 2

Input:

10 2 9
1 2 2 2 1 1 1 1 1 1 
3 7 2
2 3 1
3 7 2
6 9 2
2 5 2
2 6 2
3 8 2
5 6 1
2 9 1

Output:

2
0
2
0
3
3
2
2
5