CERN is an international institution focused on nuclear research and particle physics. The particle accelerator system at CERN is used to conduct experiments involving the collision of particles at high speeds. We consider $N$ particles arranged in a sequence. Each particle is defined by its type $v_{i}$, represented by a positive integer between 1 and $N$. In the latest research, it is necessary to conduct $Q$ experiments. In the $i$-th experiment, we observe all particles from the $l_{i}-th$ to the $r_{i}-th$ in the sequence ($l_{i} < r_{i}$). Among the observed particles, we can choose any two particles of different types and collide them in the accelerator, causing both particles to be destroyed. We repeat this collision process as long as there are two particles of different types among the observed particles. The experiment ends either when all observed particles are destroyed or when there are some particles of the same type remaining. Of course, depending on the order in which we collide the particles, it is possible to end up with various types of particles at the end. Since particle collision is not cheap, you have decided to conduct experiments only in theory. Now, for each experiment, you are interested in how many types of particles exist such that it is possible to end the experiment with some remaining particles of that type.
Input
The first line contains two positive integers $N$ and $Q$, the number of particles and the number of experiments, respectively. The next line contains a sequence of $N$ numbers $v_{1}$, . . . , $v_{N}$, representing the types of particles. In each of the following $Q$ lines, there is a pair of two positive integers $l_{i}$ and $r_{i}$ ($1 \le l_{i} < r_{i} \le N$), representing the interval of observed particles in the $i$-th experiment.
Output
For each of the $Q$ experiments, print in a separate line the requested number of types of particles with which it is possible to end the experiment.
Constraints
Subtask 1 (13 points): $v_{i} \le 10$ for each $i = 1$, . . . , N.
Subtask 2 (19 points): There are at most two particles of each type.
Subtask 3 (17 points): N, $Q \le 2000$
Subtask 4 (19 points): N, $Q \le 100$, 000
Subtask 5 (32 points): There are no additional constraints. April $28^{st}$ 2024 Example input 11 5 2 4 2 3 4 4 3 1 4 4 4 1 4 2 8 6 9 8 10 8 11 output
Subtask 1 (4 points): —
Subtask 1 (1 points): 1 Explanation of the first example: In the first experiment, we can collide particles of types 3 and 4, leaving two particles of type 2 remaining. There is no way to end up with any other type of particles. In the second experiment, it is possible to end up with some remaining particles of each type. In the fourth and fifth experiments, regardless of the choice of collisions, some particles of type 4 will remain at the end.
Example 1
11 5 2 4 2 3 4 4 3 1 4 4 4 1 4 2 8 6 9 8 10 8 11
1 4 1 1 1
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.