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.