Sumex

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

You are given a sequence a_1,,a_na\_1,\dots , a\_n and qq independent queries. In each query you are given two integers ll and rr. Consider the sequence a_l,a_l+1,,a_ra\_l , a\_{l+1}, \dots , a\_r. Your task is to compute the sum of the minimum excluded element of all sequences of form a_i,a_i+1,,a_ja\_i , a\_{i+1}, \dots , a\_j, for lijrl ≤ i ≤ j ≤ r.

The minimum excluded element of a sequence is the smallest non-negative integer that does not appear in the sequence. For example, for the sequence 00, 11, 44, 22 it is 33, but the for the sequence 11, 22, 33, 44 it is 00.

입력

The first line of the input contains the integers nn and qq. The second line contains nn integers a_1,a_2,,a_na\_1, a\_2, \dots , a\_n, representing the initial sequence. Each of the next qq lines contains two integers ll and rr, describing each query.

출력

The output should contain the answers to the qq queries in order, each on a new line.

제한

  • 1n,q21051 ≤ n, q ≤ 2 · 10^5
  • 0a_in0 ≤ a\_i ≤ n
  • 1lrn1 ≤ l ≤ r ≤ n

힌트

Explanation for the first queries:

SubsequenceMin. excl. elem.
0011
1100
00, 1122
Total:33

Explanation for the second queries:

SubsequenceMin. excl. elem.
2200
0011
1100
22, 0011
00, 1122
22, 00, 1133
Total:77

Explanation for the third query:

SubsequenceMin. excl. elem.
0011
00, 1122
00, 11, 2233
00, 11, 22, 0033
00, 11, 22, 00, 1133
00, 11, 22, 00, 11, 3344
1100
11, 2200
11, 22, 0033
11, 22, 00, 1133
11, 22, 00, 11, 3344
2200
22, 0011
22, 00, 1133
22, 00, 11, 3344
0011
00, 1122
00, 11, 3322
1100
11, 3300
3300
Total:3939