Codeforces Round 136 (Div. 1)
B
Little Elephant and Array
Codeforces
1800
原题
← AC →
翻译中…

The Little Elephant loves playing with arrays. He has array $*a*$, consisting of $*n*$ positive integers, indexed from 1 to $*n*$. Let's denote the number with index $*i*$ as $*a*_{*i*}$.

翻译中…

Additionally the Little Elephant has $*m*$ queries to the array, each query is characterised by a pair of integers $*l*_{*j*}$ and $*r*_{*j*}$ $(1 ≤ *l*_{*j*} ≤ *r*_{*j*} ≤ *n*)$. For each query $*l*_{*j*}, *r*_{*j*}$ the Little Elephant has to count, how many numbers $*x*$ exist, such that number $*x*$ occurs exactly $*x*$ times among numbers $*a*_{*l*_{*j*}}, *a*_{*l*_{*j*} + 1}, ..., *a*_{*r*_{*j*}}$.

翻译中…

Help the Little Elephant to count the answers to all queries.

翻译中…

Input

翻译中…

The first line contains two space-separated integers $*n*$ and $*m*$ $(1 ≤ *n*, *m* ≤ 10^{5})$ — the size of array $*a*$ and the number of queries to it. The next line contains $*n*$ space-separated positive integers $*a*_{1}$, $*a*_{2}$, $...$, $*a*_{*n*}$ $(1 ≤ *a*_{*i*} ≤ 10^{9})$. Next $*m*$ lines contain descriptions of queries, one per line. The $*j*$-th of these lines contains the description of the $*j*$-th query as two space-separated integers $*l*_{*j*}$ and $*r*_{*j*}$ $(1 ≤ *l*_{*j*} ≤ *r*_{*j*} ≤ *n*)$.

翻译中…

Output

翻译中…

In $*m*$ lines print $*m*$ integers — the answers to the queries. The $*j*$-th line should contain the answer to the $*j*$-th query.

翻译中…

样例

Input #1
7 2
3 1 2 2 3 3 7
1 7
3 4
Output #1
3
1
InputCopy OutputCopy
题目信息
题号
220B
时间限制
4 s
内存限制
256 MB
标签
构造
数据结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。