Angry Chef  Crispy Chips

All submissions for this problem are available.
Did you know that potato was the first food that was ever grown in space ? Today is a big day for chef Crum, as he was called to make potato dishes for the people of the Valley of Food. He got angry knowing someone said that his potatoes were thick and so he started making them too thin and crisp ! (and thus invented potato chips :) ). There are N persons sitting in a row ( numbered 0 to N1 ) and you are given an array V, where V[i] is the village number, where the i^{th} person is from.
In each of the R rounds, Po serves potato chips to a group of people sitting continuously (a subarray). Shifu is worried that, if in a round, more than K people from a village are served potato chips, others may protest and that leads to disruption of outer peace. To estimate the damage of a round, he wants to know how many distinct villages are there such that more than K people from each of them are served in that round.
Input
First line contains two integers N K ( N is the number of persons, 1 <= N <= 100,000 and K is the limit in each round 0 <= K <= N ). Next line contains N numbers, the array V (as described above. 0 <= V[i] <= 100,000,000 ). Third line contains R (number of rounds, 1 <= R <= 100,000 ). R rounds follow, each in a new line, having integers i j (0 <= i <= j < N ). Po serves all the persons [ i, i+1, ... , j ] in that round.
Output
For each of the R rounds, print the answer in a new line.
Example
Input: 8 2 3 1 2 2 1 1 2 1 3 0 5 2 4 1 7 Output: 1 0 2 Explanation: V[0..5] = { 3, 1, 2, 2, 1, 1 } : Only Village 1 occurs more than K ( = 2) times. V[2..4] = { 2, 2, 1} : None of the villages occur more than 2 times. V[1..7] = { 1, 2, 2, 1, 1, 2, 1 } : Villages 1 and 2 occur more than 2 times.
Warning : Large input / output. You may have to use efficient input / output methods if you are using languages with heavy input / output overload. Eg: Prefer using scanf/printf to cin/cout for C/C++
Note : There are multiple test sets, and the judge shows the sum of the time taken over all test sets of your submission, if Accepted. Time limit on each test set is 2 sec
Author:  flying_ant 
Tester:  masked_zorro 
Editorial  http://discuss.codechef.com/problems/KCHIPS 
Tags  cook13, flying_ant, medium 
Date Added:  7082011 
Time Limit:  0.24186 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 