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

Bài tập thuộc lộ trình

3 lộ trình

Đế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 NN integers and QQ queries. For each inclusive range [l,r][l,r], count the number of distinct values among positions ll through rr. The array never changes.

Input

The first line contains N,QN,Q. The second line contains NN array values. Each of the next QQ lines contains l,rl,r.

Output

Print QQ lines, one answer per query in the original order.

Subtasks

  • Subtask 1 (20 points): 1≤N≤301\le N\le 30; 1≤Q≤301\le Q\le 30; 1≤ai≤10000000001\le a_i\le 1000000000; 1≤l≤r≤N1\le l\le r\le N.
  • Subtask 2 (30 points): 1≤N≤22001\le N\le 2200; 1≤Q≤22001\le Q\le 2200; 1≤ai≤10000000001\le a_i\le 1000000000; 1≤l≤r≤N1\le l\le r\le N.
  • Subtask 3 (50 points): 1≤N≤2000001\le N\le 200000; 1≤Q≤2000001\le Q\le 200000; 1≤ai≤10000000001\le a_i\le 1000000000; 1≤l≤r≤N1\le l\le r\le N.

Examples

Input

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

Output

2
3
3

Explanation

Range [1,3][1,3] contains 3,2,33,2,3 and has 22 distinct values. Range [2,4][2,4] contains 2,3,12,3,1 and has 33.