Another LISTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 1291 Accepted Submission (s): 451
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 Input
130 0 2
Sample Output
Case #1: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)
Recommendzhouzeyong | We have carefully selected several similar problems for you:3572 2389 3584 3293 1255 idea: Just insert from the left to find the vacancy, from the 1~n to record their position with the line segment tree, and then to them The location of the LIS is good AC code
#include <stdio.h> #include <string.h> #define MAX (A, B) (a>b?a:b) int A[100010];int node[100010<<2 ],d[100010],len,dp[100010];void Build (int l,int r,int tr) {node[tr]=r-l+1;if (l==r) return;int mid= (l+r) >>1; Build (l,mid,tr<<1); build (mid+1,r,tr<<1|1); node[tr]=node[tr<<1]+node[tr<<1|1];} int bin (int x) {int L=1,r=len;while (l<=r) {int mid= (l+r) >>1;if (X>dp[mid]) l=mid+1;elser=mid-1;} return l;} void Insert (int pos,int num,int l,int r,int tr) {if (l==r) {D[num]=l;node[tr]=0;return;} int mid= (L+R) >>1;node[tr]--;if (pos<=node[tr<<1]) {insert (pos,num,l,mid,tr<<1);} Elseinsert (pos-node[tr<<1],num,mid+1,r,tr<<1|1);} int main () {int t,c=0;scanf ("%d", &t), while (t--) {int n;scanf ("%d", &n), int i;for (i=1;i<=n;i++) {scanf ("%d", &a[i]);DP [i]=0;} Build (1,n,1), for (i=n;i>0;i--) {insert (a[i]+1,i,1,n,1);} Len=0;/*for (i=1;i<=n;i++) {printf ("%d\n", D[i]);} */printf ("Case #%d:\n", ++c); for (i=1;i<=n;i++) {int k=bin (d[i]); Len=max (LEN,K);DP [k]=d[i];p rintf ("%d\n", Len);} printf ("\ n");}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdoj topic 3564 Another LIS (segment tree single point update, LIS)