Under construction

Still being built. Things may change

CERN

Time limit4sMemory limit1024 MB

Summary
For each range of particles, count the types that can survive as the last remaining type after colliding pairs of different types.
Level

Medium7 of 10

Topics
Array, Hash map, Math, Sorting
Solved
No attempts yet

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 NN particles in a row. Each particle has a type viv_i, a natural number between 11 and NN.

You will run QQ experiments. In the ii-th experiment, you observe the particles from position lil_i to position rir_i (li<ril_i < r_i). 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 NN and QQ, the number of particles and the number of experiments.

The second line contains NN numbers v1,…,vNv_1, \dots, v_N, the types of the particles in order.

Each of the next QQ lines contains two natural numbers lil_i and rir_i (1≤li<ri≤N1 \le l_i < r_i \le N), the observed interval in the ii-th experiment.

Output

For each of the QQ 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, 2≤N≤5000002 \le N \le 500000 and 1≤Q≤5000001 \le Q \le 500000.

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.

Examples1

  1. Example 1

    Input
    11 5
    2 4 2 3 4 4 3 1 4 4 4
    1 4
    2 8
    6 9
    8 10
    8 11
    
    Expected output
    1
    4
    1
    1
    1