Yam told Alter about the following problem:
You are given an array of $$$n$$$ elements, $$$a_1, a_1, \dots, a_n$$$. You can perform the following 2 operations any number of times in any order:
You want to minimize the number of operations of type (2) performed in order to turn the array into a permutation. We define this number to be the value of an array.
Now, Yam gives Alter $$$q$$$ queries, asking for the value of a subarray. Since Alter can only process one query at a time, he asks you to solve the problem.
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$).
The following line contains $$$n$$$ integers, the $$$i$$$-th of which is $$$a_i$$$ ($$$1\le a_i \le 10^9$$$).
The next $$$q$$$ lines contain two integers $$$l$$$, $$$r$$$, which describe the left and right endpoints (inclusive) of the queries ($$$1\le l \le r \le n$$$).
—
Tests in subtasks are numbered from $$$1−20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Tests $$$1-2$$$ satisfy $$$n, q\le 1000$$$.
Tests $$$3-8$$$ guarantee that all $$$a_i$$$ are distinct.
Tests $$$9-12$$$ satisfy no additional constraints.
For each query, output a single integer — the value of the subarray.
5 34 5 6 2 13 52 43 4
3 3 4
5 33 8 4 2 42 53 41 4
5 2 2
In the first sample test case:
The first query asks for the answer to the array $$$[6, 2, 1]$$$. One way to achieve the minimum number of type (2) operations is:
The first sample test case satisfies the conditions of tests $$$3-8$$$.
—
Problem Idea: jay_jayjay
Problem Preparation: jay_jayjay
Occurrences: Advanced I