NC222431. [USACOFeb2021P]NoTimetoDry
描述
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 Q candidate ranges , each described by two integers (a,b) with
giving the indices of endpoints of the range a…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 N and Q.The next line contains an array of N integers representing the desired color for each fence segment.
The next Q lines each contain two space-separated integers aa and bb representing a candidate range to possibly paint.
输出描述
For each of the Q 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
输出:
2 3 3 3
说明:
In this example, the sub-range corresponding to the desired pattern
1 1 2
requires two strokes to paint. The sub-range corresponding to the desired pattern
2 1 1 2
requires three strokes to paint. The sub-range corresponding to the desired pattern
1 2 2 1 1 2
requires three strokes to paint. The sub-range corresponding to the desired pattern
1 2 3 2
requires three strokes to paint.