#P13968. [VKOSHP 2024] Classics

[VKOSHP 2024] Classics

题目描述

You are probably familiar with the classic problem of finding the longest increasing subsequence in an array. Let aa be an array consisting of nn integers. A subsequence i1<i2<<iki_1 < i_2 < \ldots < i_k is called increasing\textit{increasing} if ai1<ai2<<aika_{i_1} < a_{i_2} < \ldots < a_{i_k}. The longest increasing subsequence is the increasing subsequence of maximum length. Of course, we will not ask you to solve the classic problem; you will have to solve its more complicated version...

Initially, there is an empty array aa. Then, the numbers 1,2,,n1, 2, \ldots, n are added to the array in this order. The number ii is added to the array at position pip_i. Positions in the array are numbered with integers from 11 to kk, where kk is the current size of the array. When adding an element at position pp in an array of size kk, all elements that previously had positions from pp to kk are shifted one position to the right, and the current element is added to the freed space.

Your task is to determine the length of the longest increasing subsequence in the array after each addition of a new element.

输入格式

The first line contains one integer nn (1n2000001 \le n \le 200\,000) --- the number of added elements.

The second line contains nn integers p1,p2,,pnp_1, p_2, \ldots, p_n (1pii1 \le p_i \le i) --- pip_i denotes the position where element ii is added.

输出格式

Output nn integers --- the length of the longest increasing subsequence of the array after each addition of a new element.

5
1 2 1 3 4
1
2
2
2
3
1
1
1

提示

The array in the first example changed as follows: $[] \to [1] \to [1, 2] \to [3, 1, 2] \to [3, 1, 4, 2] \to [3, 1, 4, 5, 2]$.