Longest Loose Segment

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

문제

A list AA is called loose if max(A)+min(A)>len(A)\max(A) + \min(A) > \text{len}(A).

Today Rikka got a list AA of length nn. She wants to find the longest segment \[l,r]\[l, r] in AA such that list \[A_l,A_l+1,,A_r]\[A\_l, A\_{l + 1}, \ldots, A\_r] is loose.

Rikka will make mm turns with list AA. On each turn, Rikka will perform one or more given operations in sequence. Each operation is swapping two elements in list AA. Your task is to calculate the length of the longest loose segment of AA and the resulting list after each turn.

Note that the operations on turn ii are performed on the list that was the result of turn (i1)(i - 1).

입력

The first line contains two integers nn and mm (1n1061 \leq n \leq 10^6 and 1m301 \leq m \leq 30).

The second line contains nn integers A_iA\_i (106A_i106-10^6 \leq A\_i \leq 10^6) that constitute the initial list AA.

Then follow mm descriptions of the turns. For each turn, the first line contains a single integer kk (1k1061 \leq k \leq 10^6), the number of swaps. Then kk lines follow: each of them contains two integers u_iu\_i and v_iv\_i (1u_i,v_in1 \leq u\_i, v\_i \leq n and u_iv_iu\_i \neq v\_i) such that Rikka will swap A_u_iA\_{u\_i} and A_v_iA\_{v\_i} in this operation.

It is guaranteed that k106\sum k \leq 10^6.

출력

On the first line, output a single integer: the length of the longest loose segment of AA.

Then output mm lines. On each of them, print a single integer: the length of the longest loose segment of the resulting list after each turn.