#520
Unrated
No Time to Dry
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Bessie has recently received a painting set, and she wants to paint the long fence at one end of her pasture. The fence consists of NN consecutive 1-meter segments (1N21051\le N\le 2\cdot 10^5). Bessie has NN different colors available, which she labels with the letters 11 through NN in increasing order of darkness (11 is a very light color, and NN is very dark). She can therefore describe the desired color she wants to paint each fence segment as an array of NN integers.

Initially, all fence segments are uncolored. Bessie can color any contiguous range of segments with a single color in a single brush stroke as long as she never paints a lighter color over a darker color (she can only paint darker colors over lighter colors).

For example, an initially uncolored segment of length four can be colored as follows:

0000 -> 1110 -> 1122 -> 1332

Unfortunately, Bessie doesn't have time to waste watching paint dry. Thus, Bessie thinks she may need to leave some fence segments unpainted! Currently, she is considering QQ candidate ranges (1Q21051\le Q\le 2\cdot 10^5), each described by two integers (a,b)(a,b) with 1abN1 \leq a \leq b \leq N giving the indices of endpoints of the range aba \ldots b of segments to be painted.

For each candidate range, what is the minimum number of strokes needed to paint every fence segment inside the range with its desired color while leaving all fence segments outside the range uncolored? Note that Bessie does not actually do any painting during this process, so the answers for each candidate range are independent.

입력

The first line contains NN and QQ.

The next line contains an array of NN integers representing the desired color for each fence segment.

The next QQ lines each contain two space-separated integers aa and bb representing a candidate range to possibly paint.

출력

For each of the QQ candidates, output the answer on a new line.

예제 입력 1

8 4
1 2 2 1 1 2 3 2
4 6
3 6
1 6
5 8

예제 출력 1

2
3
3
3

점수

Test cases 1-2 satisfy N,Q100N,Q\le 100.Test cases 3-5 satisfy N,Q5000N,Q\le 5000.In test cases 6-10, the input array contains no integer greater than 1010. Test cases 11-20 satisfy no additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.