luogu#P4919. Marisa采蘑菇
Marisa采蘑菇
Background
is a girl who loves magic, and the high-firepower and flashy Bagua Furnace is her commonly used weapon. As time goes on, also wants to upgrade the firepower of her Bagua Furnace, so she decides to go to the Magic Forest to pick mushrooms to obtain materials for experiments.
Problem Description
arrives in the forest and sees a row of colorful mushrooms. Their colors are . Since she is very picky, she will only pick those “magic mushrooms”.
A mushroom is called a “magic mushroom” if and only if it is within a given interval, and within this given interval, the difference between the number of mushrooms with the same color as it (including itself) and the number of mushrooms of that color outside this given interval is less than or equal to a given constant .
Now will make queries. In the -th query, you need to answer how many different colors of “magic mushrooms” there are in .
Input Format
The first line contains three integers .
The second line contains positive integers, representing the color of each mushroom.
Then follow lines, each containing two positive integers , representing the left endpoint and right endpoint of the interval queried by . The data guarantees that .
Output Format
Output lines. Each line contains an integer , representing the number of different colors of “magic mushrooms” in the query interval.
6 3 2
2 3 2 4 1 2
1 2
2 4
1 6
2
3
3
Hint
Sample Explanation:
Let the constant . For the interval :
. Mushrooms of color appear time inside , and times outside the interval. The difference is .
. Mushrooms of color appear time inside , and times outside the interval. The difference is .
So there are two different colors of magic mushrooms in .
Constraints:
For all testdata, , .
For of the testdata, , .
For of the testdata, , .
For of the testdata, , .
ps: Please pay attention to input efficiency.
Translated by ChatGPT 5