dquery

Given a sequence of N numbers a1, a2, ..., aN, and a number of d-queries. A d-query is a pair (i, j) (1 ≤ ijN). For each d-query (i, j), you have to return the number of distinct elements in the subsequence ai, ai + 1, ..., aj.

Input

  • Line 1: N (1 ≤ N ≤ 200000).
  • Line 2: N numbers a1, a2, ..., aN (1 ≤ ai ≤ 106).
  • Line 3: Q (1 ≤ Q ≤ 200000).
  • In the next Q lines, each line contains 2 numbers, i, j representing a d-query (1 ≤ ijN).

Output

  • For each d-query (i, j), print the number of distinct elements in the subsequence ai, ai + 1, ..., aj in a single line.

Sample Input 1

5
1 1 2 1 3
3
1 5
2 4
3 5

Sample Output 1

3
2
3

Sample Input 2

10
8 1 4 3 10 1 7 4 8 1
5
1 1
3 4
2 9
2 2
4 10

Sample Output 2

1
2
6
1
6

Time Limit: 1 Seconds
Memory Limit: 1024MB
Your best score: 0
Source: Classic Problem

Subtask Score
1 100
2 0