#FT0000253. Tulip và các con số (Tulip And Numbers)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tulip và các con số (Tulip And Numbers)
Tulip And Numbers
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Tulip writes positive integers in a row, never writing a number smaller than the preceding one. Therefore, the sequence is nondecreasing.
For each query i j, count the number of distinct values among positions through , inclusive. Repeated occurrences of the same value count once.
Input
- The first line contains .
- The second line contains nondecreasing positive integers .
- The next lines each contain .
Output
Print lines, each giving the number of distinct values in the corresponding query interval.
Subtasks
-
Subtask 1 (20 points): ; ; ; .
-
Subtask 2 (30 points): ; ; ; .
-
Subtask 3 (50 points): ; ; ; .
Examples
Input
5 3
1 2 2 4 5
1 2
1 5
4 5
Output
2
4
2
Explanation
The interval contains and , so its answer is . The full interval contains distinct values , giving . The interval contains , giving . Each answer occupies one line without a case label.