#P4113. [HEOI2012] 采花

    ID: 3030 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2012莫队各省省选树状数组河北排序主席树前缀和

[HEOI2012] 采花

Description

Xiao Xun'er is the princess of an ancient kingdom, and one of her hobbies is picking flowers.

Today the weather is fine and sunny, so the princess went to the newly built palace garden in the morning to pick flowers.

The garden is large enough to hold nn flowers in total, with cc colors labeled by integers 1c1 \sim c. The flowers are arranged in a single row to make it convenient for the princess to pick. After each picking session, the princess counts how many different colors she has collected; the more colors, the happier she is. At the same time, she has a quirk: she does not allow that, among the flowers she finally picks, any color appears only once. For this reason, every time she picks a flower, either she has already picked a flower of that color before, or her accurate intuition tells her she will be able to pick that color again.

Due to time constraints, the princess can only walk through one continuous segment of the garden to pick flowers, so the maid Fuhan Jie arranged mm trips after considering various factors. For each trip, you are asked how many different colors the princess can collect.

Input Format

The first line contains three space-separated integers, representing the number of flowers nn, the number of colors cc, and the number of trips mm.

The second line contains nn space-separated integers. The ii-th integer is the color xix_i of the ii-th flower.

From line 33 to line (m+2)(m + 2), each line contains two integers l,rl, r. On line (i+2)(i + 2), the numbers represent that the ii-th trip covers flowers from the ll-th to the rr-th.

Output Format

Output mm lines, one integer per line. The integer on the ii-th line is the number of different colors the princess can collect on the ii-th trip.

5 3 5
1 2 2 3 1
1 5
1 2
2 2
2 3
3 5
2
0
0
1
0

Hint

Explanation for Sample 1:

There are five flowers, and their colors are 1, 2, 2, 3, 11,~2,~2,~3,~1.

For the first trip, the picking interval is [1,5][1, 5]. She can pick the flowers at positions 1, 2, 3, 51,~2,~3,~5, so there are two different colors, 11 and 22.

For the second trip, the picking interval is [1,2][1, 2], but the flowers of colors 11 and 22 each appear only once, so the princess cannot pick any flower.

For the third trip, the picking interval is [2,2][2, 2], but color 22 appears only once, so the princess cannot pick any flower.

For the fourth trip, the picking interval is [2,3][2, 3]. She can pick the flowers at positions 2, 32,~3, and there is only one color, 22.

For the fifth trip, the picking interval is [3,5][3,5], but colors 1,2,31, 2, 3 each appear only once, so the princess cannot pick any flower.

Constraints:

This problem uses bundled multi-test-point evaluation and has two subtasks.

For subtask 11 (worth 100100 points), it is guaranteed that 1n,c,m3×1051 \leq n, c, m \leq 3 \times 10^5.

For subtask 22 (worth 100100 points), it is guaranteed that 1n,c,m2×1061 \leq n, c, m \leq 2 \times 10^6.

For all test points, it is guaranteed that 1xic1 \leq x_i \leq c, 1lrn1 \leq l \leq r \leq n.

Translated by ChatGPT 5