问题2444--Longest Increasing Subsequence

2444: Longest Increasing Subsequence

时间限制: 120 Sec  内存限制: 128 MB
提交: 3  解决: 1
[提交] [状态] [讨论版] [命题人:]

题目描述

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]2 f[2]2 · · · f[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.

输入

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.
• 2 n 5000
• 1 ai n
• The number of test cases does not exceed 10.

输出

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

样例输入

5
2 5 3 1 4

样例输出

5 13 0 8 0

来源/分类


[提交] [状态]