#ds302. 区间不同数之和

区间不同数之和

Sum of Distinct Numbers in an Interval

Problem Description

You are given nn numbers a1,a2,…,ana_1, a_2, \dots, a_n.

There are qq queries. Each query gives an interval [l,r][l, r]; compute the sum of the distinct numbers in that interval, i.e. if the same number appears multiple times it is counted only once.

Input Format

The first line contains two integers nn and qq (1≤n,q≤2×1051 \le n, q \le 2 \times 10^5).

The next line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1 \le a_i \le n).

The following qq lines each contain two integers ll and rr (1≤l≤r≤n1 \le l \le r \le n).

Output Format

For each query, output one line containing the answer.

Sample Input

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

Sample Output

6
5
5
2
6

Constraints

1≤n,q≤2×1051 \le n, q \le 2 \times 10^5, 1≤ai≤n1 \le a_i \le n, 1≤l≤r≤n1 \le l \le r \le n.