Zip-line

시간 제한3초메모리 제한1024 MB

요약
나무 높이 배열이 주어질 때, 한 원소의 값을 바꾸는 m개의 독립적인 질의마다 변경 후 가장 긴 증가 부분 수열의 길이를 구한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 이분 탐색, 누적 합, 정렬
정답자
아직 제출이 없습니다

문제

Vasya has decided to build a zip-line on trees of a nearby forest. He wants the line to be as long as possible but he doesn't remember exactly the heights of all trees in the forest. He is sure that he remembers correct heights of all trees except, possibly, one of them.

It is known that the forest consists of nn trees staying in a row numbered from left to right with integers from 11 to nn. According to Vasya, the height of the ii-th tree is equal to h_ih\_i. The zip-line of length kk should hang over kk (1≤k≤n1 \le k \le n) trees i_1,i_2,…,i_ki\_1, i\_2, \ldots, i\_k (i_1<i_2<…<i_ki\_1 < i\_2 < \ldots < i\_k) such that their heights form an increasing sequence, that is h_i_1<h_i_2<…<h_i_kh\_{i\_1} < h\_{i\_2} < \ldots < h\_{i\_k}.

Petya had been in this forest together with Vasya, and he now has qq assumptions about the mistake in Vasya's sequence hh. His ii-th assumption consists of two integers a_ia\_i and b_ib\_i indicating that, according to Petya, the height of the tree numbered a_ia\_i is actually equal to b_ib\_i. Note that Petya's assumptions are independent from each other.

Your task is to find the maximum length of a zip-line that can be built over the trees under each of the qq assumptions.

In this problem the length of a zip line is considered equal to the number of trees that form this zip-line.

입력

The first line of the input contains two integers nn and mm (1≤n,m≤400,0001 \leq n, m \leq 400\\,000) --- the number of the trees in the forest and the number of Petya's assumptions, respectively.

The following line contains nn integers h_ih\_i (1≤h_i≤1091 \leq h\_i \leq 10^9) --- the heights of trees according to Vasya.

Each of the following mm lines contains two integers a_ia\_i and b_ib\_i (1≤a_i≤n1 \leq a\_i \leq n, 1≤b_i≤1091 \leq b\_i \leq 10^9).

출력

For each of the Petya's assumptions output one integer, indicating the maximum length of a zip-line that can be built under this assumption.

힌트

Consider the first sample. The first assumption actually coincides with the height remembered by Vasya. In the second assumption the heights of the trees are (4,2,3,4)(4, 2, 3, 4), in the third one they are (1,2,3,3)(1, 2, 3, 3) and in the fourth one they are (1,2,3,5)(1, 2, 3, 5).

예제2

  1. 예제 1

    입력
    4 4
    1 2 3 4
    1 1
    1 4
    4 3
    4 5
    
    예상 출력
    4
    3
    3
    4
    
  2. 예제 2

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