#FT0000130. Công chúa hái hoa (Flower Picking)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Công chúa hái hoa (Flower Picking)
Flower Picking
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
A garden consists of flowers in one row. Flower has color in the range . There are independent queries, each selecting a contiguous interval .
For each query, count the number of distinct colors occurring at least twice among flowers in the interval. A color occurring once is not counted; a length-one query therefore has answer zero. Queries do not remove flowers or alter the array.
Input
- First line: .
- Second line: colors .
- Next lines: one query each.
Output
Print lines in query order: the number of colors appearing at least twice.
Subtasks
- Subtask 1 (20 points): ; ; ; , where is the maximum in this subtask.
- Subtask 2 (30 points): ; ; ; , where is the maximum in this subtask.
- Subtask 3 (50 points): ; ; ; , where is the maximum in this subtask.
Examples
Example 1
Input
5 3 5
1 2 2 3 1
1 5
1 2
2 2
2 3
3 5
Output
2
0
0
1
0
Explanation
In , colors 1 and 2 each occur twice, while color 3 occurs once, yielding 2. In , both colors occur once: 0. A length-one query yields 0. In , color 2 occurs twice: 1. In , each of colors 2, 3 and 1 occurs once: 0.
Example 2
Input
6 3 4
1 1 2 2 2 3
1 6
2 5
4 6
5 5
Output
2
1
1
0
Explanation
The sequence is 1 1 2 2 2 3. The full range has two colors occurring at least twice. Range contains one color occurring at least twice (color 2), range contains color 2 twice, and contains no duplicated color. The answers are 2, 1, 1, 0.