#K77842. Count Occurrences in Subarray

    ID: 34954 Type: Default 1000ms 256MiB

Count Occurrences in Subarray

Count Occurrences in Subarray

You are given an array of integers and a list of queries. Each query is given by three integers \(l\), \(r\), and \(x\), where \(l\) and \(r\) denote the bounds of a subarray (using 1-indexing) and \(x\) is the number to count within this subarray.

Your task is to compute, for each query, the number of times \(x\) appears in the subarray \(a[l...r]\). For example, if \(a = [1, 2, 1, 2, 3]\) and the query is \((1, 3, 1)\) then the output should be 2, since the subarray \([1,2,1]\) contains two occurrences of \(1\).

Note: The indices provided are 1-based. Make sure to handle the input and output using stdin and stdout respectively.

inputFormat

The first line contains two integers \(n\) and \(q\) — the size of the array and the number of queries respectively.

The second line contains \(n\) integers, the elements of the array \(a\).

Each of the following \(q\) lines contains three integers \(l\), \(r\), and \(x\) describing a query.

outputFormat

For each query, output a single integer on a separate line representing the number of occurrences of \(x\) in the subarray \(a[l...r]\).

## sample
5 3
1 2 1 2 3
1 3 1
2 4 2
1 5 3
2

2 1

</p>