#P15635. [2019 KAIST RUN Spring] Increasing Sequence

[2019 KAIST RUN Spring] Increasing Sequence

Problem Description

You are given a permutation of size NN. For each ii, print the number of indices j≠ij \neq i, which when removed, decreases the maximum possible length of an increasing subsequence that contains index ii.

Input Format

The first line contains an integer NN. (1≤N≤2500001 \le N \le 250000).

The next line contains NN integers A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N denoting the permutation. (1≤Ai≤N1 \le A_i \le N, all AiA_is are distinct).

Output Format

Print NN integers, separated by spaces, denoting the answers for i=1,2,3,⋯ ,Ni = 1, 2, 3, \cdots, N.

1
1
0
6
1 2 3 4 5 6
5 5 5 5 5 5
6
6 5 4 3 2 1
0 0 0 0 0 0
4
2 1 4 3
0 0 0 0
9
1 2 3 6 5 4 7 8 9
5 5 5 6 6 6 5 5 5