PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000058. Truy vấn số giá trị phân biệt (D-query)
HỌC THEO LỘ TRÌNH
3 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Truy vấn số giá trị phân biệt (D-query)
D-query
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of positive integers, determine the number of distinct values occurring in each inclusive subarray .
Array positions are numbered from to . Every query uses an inclusive interval containing both endpoints. Queries do not modify the original array and are independent of one another.
Input
First line contains . The next line contains values . The following line contains . There follow lines .
Output
Print one integer per query line, preserving the original query order.
Subtasks
- Subtask 1 (10 points): ; ; ; .
- Subtask 2 (20 points): ; ; ; .
- Subtask 3 (30 points): ; ; ; .
- Subtask 4 (40 points): ; ; ; .
Examples
Input
5
1 1 2 1 3
3
1 5
2 4
3 5
Output
3
2
3
Explanation
Range contains (three distinct values); has (two); and has (three).