PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CC0000010. Đếm màu khác nhau trong đoạn (Range Set Query)

HỌC THEO LỘ TRÌNH

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

3 lộ trình

Đếm màu khác nhau trong đoạn (Range Set Query)

Range Set Query

Source: AtCoder Version: Phuoc Hung OJ Extended

Problem Statement

There are NN colored balls in a row; ball ii has color cic_i. For each inclusive query [l,r][l,r], count the number of different colors present in that subarray. No colors change.

Input

The first line contains N,QN,Q. The second line contains NN colors cic_i. The next QQ lines each contain 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≤ci≤N1\le c_i\le N; 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≤ci≤N1\le c_i\le N; 1≤l≤r≤N1\le l\le r\le N.
  • Subtask 3 (50 points): 1≤N≤5000001\le N\le 500000; 1≤Q≤5000001\le Q\le 500000; 1≤ci≤N1\le c_i\le N; 1≤l≤r≤N1\le l\le r\le N.

Examples

Input

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

Output

2
3
1

Explanation

Query [3,3][3,3] contains just one ball and therefore one color.