There are $$$n$$$ cards, numbered from $$$1$$$ to $$$n$$$. A cutting card operation is performed as follows:
For example, for five cards $$$\{1,2,3,4,5\}$$$, they can be divided into $$$\{1\},\{2,3\},\{4,5\}$$$, $$$\{1\},\{2\},\{3\},\{4\},\{5\}$$$, or $$$\{1,2,3,4,5\}$$$, but they cannot be divided into $$$\{1\},\{2,5\},\{3,4\}$$$ because this violates the consecutive numbering principle, nor can they be divided into $$$\{1\},\{3,2\},\{4,5\}$$$ because this violates the principle of arranging in ascending order.
For another example, for the already arranged three piles of cards from left to right $$$\{1\},\{4,5\},\{2,3\}$$$, the only possible arranged sequence is $$$\{1,4,2,5,3\}$$$, and it is not possible to obtain $$$\{1,2,4,5,3\}$$$ because this violates the left-to-right traversal order, nor is it possible to obtain $$$\{1,5,2,4,3\}$$$ because this violates the taking-from-top principle.
There is a target arrangement of the cards, and you need to calculate how many different cutting card operations can obtain this target arrangement. Two cutting card operations are different if and only if the way the cards are divided into piles is different or the arrangement of the piles is different.
The target arrangement may be modified, and for each modification, the elements in the two positions of the target arrangement are exchanged, and the answer needs to be output. The modifications are persistent, meaning that previous modifications will be retained.
The first line contains two integers $$$n,Q$$$ ($$$2\le n\le 10^5,1\le Q\le 10^5$$$).
The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1\le a_i\le n$$$), representing the initial target arrangement.
The next $$$Q$$$ lines each contain two integers $$$x,y$$$ ($$$1\le x,y\le n,x\neq y$$$), representing the positions to be swapped in each modification.
Output $$$Q+1$$$ lines. The first line outputs the answer before any modifications, and the second to the $$$Q+1$$$-th lines outputs the answer after the first to the $$$Q$$$-th modifications.
4 3 1 3 2 4 2 3 1 4 4 2
3 4 1 2
In the example, there are $$$4$$$ cards, and the initial target sequence is $$$\{1,3,2,4\}$$$. There are three cutting card operations that can obtain the target sequence:
After the first swap, the target sequence becomes $$$\{1,2,3,4\}$$$. There are four cutting card operations that can obtain the target sequence: