QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB
[0]

# 3720. Longest Increasing Subsequence

Statistics

Bobo learned how to compute Longest Increasing Subsequence (LIS) in O(nlogn) in ICPCCamp.

For those who did not attend ICPCCamp as Bobo, recall LIS(a1,a2,,an) is defined as f[1]2f[2]2f[n]2 where denotes the exclusive-or (XOR) and f is calculated as follows.

for i in [1, 2, ..., n]
  f[i] = 1
  for j in [1, 2, ..., i - 1]
    if a[j] < a[i] then
      f[i] = max(f[i], f[j] + 1)

Given sequence A=(a1,a2,,an), Bobo would like to find LIS(B1),LIS(B2),,LIS(Bn) where Bi is the sequence after removing the i-th element from A.

Input

The input contains zero or more test cases and is terminated by end-of-file. For each test case:

The first line contains an integer n. The second line contains n integers a1,a2,,an.

  • 2n5000
  • 1ain
  • The number of test cases does not exceed 10.

Output

For each case, output n integers which denote LIS(B1),LIS(B2),,LIS(Bn).

Sample Input

5
2 5 3 1 4

Sample Output

5 13 0 8 0