CERN
Time limit4sMemory limit1024 MB
For each range of particles, count the types that can survive as the last remaining type after colliding pairs of different types.
Problem
CERN is an international organization that studies nuclear physics and elementary particle physics. The particle accelerator system at CERN runs experiments that collide particles at high speed.
There are particles in a row. Each particle has a type , a natural number between and .
You will run experiments. In the -th experiment, you observe the particles from position to position (). Among the observed particles, you may pick any two particles of different types and collide them. Both particles are destroyed. Repeat this while the observed particles include two particles of different types. An experiment ends when all observed particles are destroyed or when only particles of one type remain. Depending on which particles you collide and in what order, the final remaining types can differ.
Collisions are expensive, so the experiments are run only in theory. For each experiment, find the number of particle types for which the experiment can end with some number of particles of that type remaining.
Input
The first line contains the natural numbers and , the number of particles and the number of experiments.
The second line contains numbers , the types of the particles in order.
Each of the next lines contains two natural numbers and (), the observed interval in the -th experiment.
Output
For each of the experiments, print the answer on its own line: the number of particle types that can remain at the end of the experiment.
Constraints
In all subtasks, and .
Hint
In the first experiment, we can collide particles of types 3 and 4, which leaves two particles of type 2. No other type can remain.
In the second experiment, each type can be made to remain with some number of particles.
In the fourth and fifth experiments, some number of particles of type 4 remain no matter which collisions are chosen.