Child Ehab has a piece of Cut and Stick with an exhibit an of length n composed on it. He intends to snatch some scissors and do the accompanying to it: pick a reach (l,r) and cut out each component al, al+1, ..., ar in this reach; stick a portion of the components together in a similar request they were in the exhibit;
Correct answer will be upvoted else downvoted. Computer science.
Child Ehab has a piece of Cut and Stick with an exhibit an of length n composed on it. He intends to snatch some scissors and do the accompanying to it:
pick a reach (l,r) and cut out each component al, al+1, ..., ar in this reach;
stick a portion of the components together in a similar request they were in the exhibit;
end up with different pieces, where each piece contains a portion of the components and each component has a place with some piece.
All the more officially, he segments the arrangement al, al+1, ..., ar into aftereffects. He thinks a dividing is lovely if for each piece (aftereffect) it holds that, assuming it has length x, no worth happens rigorously more than ⌈x2⌉ times in it.
He didn't pick a reach yet, so he's pondering: for q ranges (l,r), what is the base number of pieces he really wants to parcel the components al, al+1, ..., ar into with the goal that the dividing is delightful.
A succession b is an aftereffect of an exhibit an if b can be acquired from a by erasing a few (perhaps zero) components. Note that it doesn't need to be adjoining.
Input
The principal line contains two integers n and q (1≤n,q≤3⋅105) — the length of the exhibit an and the number of questions.
The subsequent line contains n integers a1, a2, ..., an (1≤
Every one of the following q lines contains two integers l and r (1≤l≤r≤n) — the scope of this question.
Output
For each question, print the base number of aftereffects you wanted to segment this reach into so the dividing is delightful. We can demonstrate such dividing consistently exists.
Step by step
Solved in 3 steps with 1 images