Subsegment Set

5

2 votes
Easy, Easy_Medium
Problem

An array containing n elements is given. Find number of distinct contiguous subsegments of length l, each containing at least k different elements. If you sort any two segments of length l, and  ai=bi,1il, then both the segments are considered to be same, and is counted only once. 

Input 

First line contains two space seperated integers n and q, size of array and number of queries respectively.

Next line contains n space seperated integers.

Next q lines contains two space separated integers lk,  l is the size of subsegment and k is the number of distinct elements in each subsegment.

 

Output

For each query print on a new line, the number of distinct contiguos subsegments of length l,  each  of which contains at least k different elements.

 

Constraints

1n105

1ai105

1q100

1kn

1l109

 

Sample Input
12 1
1 2 1 1 2 2 3 3 4 5 5 5
3 2
Sample Output
7
Time Limit: 10
Memory Limit: 256
Source Limit:
Explanation

The seven different contigous segments are [1,3],[4,6],[5,7],[6,8],[7,9],[8,10],[9,11].

After sorting all seven segments mentioned above,

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

It is clear than all the above segments are distinct. Also all segments contains atleast 2 distinct elements.

Contributers:
Editor Image

?