아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Longest Loose Segment

시간 제한2초메모리 제한256 MB

요약
여러 번의 교환을 거친 뒤, 최댓값과 최솟값의 합이 길이보다 큰 가장 긴 부분 배열의 길이를 구한다.
난이도

보통10점 중 6점

유형
배열, 구현, 정렬
정답자
아직 제출이 없습니다

문제

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 (i−1)(i - 1).

입력

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

The second line contains nn integers A_iA\_i (−106≤A_i≤106-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 (1≤k≤1061 \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 (1≤u_i,v_i≤n1 \leq u\_i, v\_i \leq n and u_i≠v_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 ∑k≤106\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.

예제1

  1. 예제 1

    입력
    5 2
    1 2 -2 3 4
    1
    2 3
    1
    1 2
    
    예상 출력
    2
    3
    4