luogu#P10749. [COI 2024] CERN
[COI 2024] CERN
Background
Source: https://hsin.hr/hio2024/. This translation comes from Wenxin Yiyan. If you have a better translation, please provide it in the discussion section.
Problem Description
CERN is an international organization focusing on nuclear research and particle physics. CERN's particle accelerator system is used for high-speed particle collision experiments.
We consider particles arranged in a sequence. Each particle is defined by its type , where is a positive integer between and .
In the latest research, experiments need to be conducted. In the -th experiment, we observe all particles in the sequence from the -th to the -th (where ). Among the observed particles, we may choose any two particles of different types and collide them in the accelerator, causing both particles to be destroyed. We repeat this collision process until there are no two particles of different types among the observed particles. The experiment ends when all observed particles are destroyed, or only particles of the same type remain. Of course, depending on the order in which we choose particles to collide, different types of particles may remain in the end.
Since particle collisions are expensive, you decide to conduct the experiments only in theory. Now, for each experiment, you are interested in how many particle types are such that, when the experiment ends, it is possible that particles of that type remain.
Input Format
The first line contains two positive integers and , representing the number of particles and the number of experiments.
The second line contains numbers , representing the types of the particles.
In the next lines, each line contains two positive integers and (), representing the particle interval observed in the -th experiment.
Output Format
For each experiment, output on a separate line the number of particle types that can possibly remain when the experiment ends.
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
Hint
Sample Explanation
In the first experiment, we can collide a type particle with a type particle, leaving two type particles. It is impossible to end up with any other type of particle.
In the second experiment, it is possible that some particles of every type remain in the end.
In the fourth and fifth experiments, no matter which collision method is chosen, some type particles will remain in the end.
Constraints
Across all subtasks, and .
- Subtask 1 (13 points): For each , .
- Subtask 2 (19 points): Each particle type appears at most twice.
- Subtask 3 (17 points): .
- Subtask 4 (19 points): .
- Subtask 5 (32 points): No additional constraints.
Translated by ChatGPT 5