#6167. [VKOSHP 2024] Classics

[VKOSHP 2024] Classics

[VKOSHP 2024] Classics

题目描述

You are probably familiar with the classic problem of finding the longest increasing subsequence in an array. Let $a$ be an array consisting of $n$ integers. A subsequence $i_1 < i_2 < \ldots < i_k$ is called $\textit{increasing}$ if $a_{i_1} < a_{i_2} < \ldots

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 $n$ ($1 \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 (1≤pi≤i1 \le p_i \le i) --- pip_i denotes the position where element ii is added.

输出格式

Output $n$ 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]$. 标签: P13968|动态规划 DP|平衡树|树状数组|2024

来源

P13968|[VKOSHP 2024] Classics