Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 1361 Accepted Submission (s): 492
Problem Descriptionthere is a sequence firstly empty. We begin to add number from 1 to N to the sequence, and every time we just add a single number to the sequence at a specif IC position. Now, we want to know length of the LIS (longest increasing subsequence) after every time ' s Add.
Inputan integer t (t <=), indicating there is t test cases.
For every test case, a integer n (1 <= n <= 100000) comes first, then there is N numbers, the k-th number Xk means That we add number K at position Xk (0 <= Xk <= k-1). See hint for more details.
Outputfor The k-th test case, first output ' case #k: ' In a separate line and then followed N lines indicating the answer. Output a blank line after every test case.
Sample Input130 0 2
Sample outputcase #1:112
HintIn the sample, we add three numbers to the sequence, and form three sequences.a. 1b. 2 1c. 2 1 3
Authorstandy
Source2010 acm-icpc multi-university Training Contest (--host by UESTC idea: because it is from large to small interpolation, then we only need to know the final sequence, and then the LIS can be asked again. You can use the line tree to find the final sequence, from the back to the beginning there are n slots, for each number of insertion position a[i], it should be placed in the left to the right of the a[i] space, the space is occupied after the number. The problem is equivalent to give the number of N, multiple operations, find out the number of K1, and then delete it, continue to find the number of K2 ...
#include <bits/stdc++.h>using namespacestd;Const intN =100000+5;#defineLson RT << 1, L, M#defineRson RT <<1|1, M + 1, RintNum[n <<2];intA[n], pos[n], ans[n], res[n], N;voidBuildintRtintLintR) {Num[rt]= R-l +1; if(L = = r)return ; intm = (L + r) >>1; Build (Lson); Build (Rson);}voidUpdateintRtintLintRintKintv) {if(L = =R) {Pos[l]=v; NUM[RT]=0; return; } intm = (L + r) >>1; if(k > Num[rt <<1]) Update (Rson, K-num[rt <<1], V); ElseUpdate (Lson, K, v); NUM[RT]= Num[rt <<1] + num[rt <<1|1];}intLis[n], Len;voidsolve () {Len=1; lis[0] =0; for(inti =1; I <= N; ++i) {intp = upper_bound (lis, Lis + len, pos[i])-LIS-1; Lis[p+1] =Pos[i]; Ans[i]= p +1; if(P +1= Len) len++; }}intMain () {//freopen ("In.txt", "R", stdin); int_, cas =1; scanf"%d", &_); while(_ --) {scanf ("%d", &N); Build (1,1, N); //puts ("-----BUG-----"); for(inti =1; I <= N; ++i) {scanf ("%d", A + i); a[i]++; } for(inti = n; I >=1; -i) Update (1,1, N, A[i], i); Solve (); for(inti =1; I <= N; ++i) res[Pos[i]] =Ans[i]; for(inti =2; I <= N; ++i) Res[i] = max (Res[i], res[i-1]); printf ("Case #%d:\n", cas++); for(inti =1; I <= N; ++i) printf ("%d\n", Res[i]); Puts (""); }}
View Code
Hdu 3564 Another LIS segment tree +lis