PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000008. Đếm giá trị khác nhau trên đoạn (Distinct Values Queries)
HỌC THEO LỘ TRÌNH
3 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm giá trị khác nhau trên đoạn (Distinct Values Queries)
Distinct Values Queries
Source: CSES Version: Phuoc Hung OJ Extended
Problem Statement
You are given integers and queries. For each inclusive range , count the number of distinct values among positions through . The array never changes.
Input
The first line contains . The second line contains array values. Each of the next lines contains .
Output
Print lines, one answer per query in the original order.
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Input
5 3
3 2 3 1 2
1 3
2 4
1 5
Output
2
3
3
Explanation
Range contains and has distinct values. Range contains and has .