| Codeforces Round 1083 (Div. 2) |
|---|
| Finished |
We call an array $$$b$$$ of length $$$m$$$ cool if and only if:
Simons has an array $$$a$$$ of size $$$n$$$. Initially, the array is a permutation$$$^{\text{∗}}$$$.
He must perform the following operation until the array is cool:
Find the minimum number of operations for Simons to perform.
$$$^{\text{∗}}$$$A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array), and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5\cdot 10^4$$$). The description of the test cases follows.
The first line contains an integer $$$n$$$ ($$$3\le n\le 5\cdot 10^5$$$) — the size of $$$a$$$.
The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1\le a_i\le n$$$, all $$$a_i$$$-s are distinct) — the array Simons has initially.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5\cdot 10^5$$$.
For each test case, print a single integer — the minimum number of operations for Simons to perform.
531 2 354 1 3 2 564 5 3 6 2 176 5 1 7 4 2 3157 4 10 12 9 14 5 3 8 11 1 15 2 13 6
01339
In the first test case, the array is cool initially, so Simons can't perform any operation. The answer is $$$0$$$.
In the second test case, Simons can perform as follows:
We can see the array is cool now. Thus, the answer is $$$1$$$.
In the third test case, Simons can perform as follows:
Thus, Simons makes the array cool in $$$3$$$ operations.
| Name |
|---|


