HDOJ question 3564 Another LIS (LIS), hdoj3564

Source: Internet
Author: User

HDOJ question 3564 Another LIS (LIS), hdoj3564
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 specific position. now, we want to know length of the LIS (Longest Increasing Subsequence) after every time's add.
InputAn integer T (T <= 10), indicating there are T test cases.
For every test case, an integer N (1 <= N <= 100000) comes first, then there are 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, then followed N lines indicating the answer. Output a blank line after every test case.
Sample Input

130 0 2
 
Sample Output
Case #1:112HintIn 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 (13) -- Host by UESTC
Recommendzhouzeyong | We have carefully selected several similar problems for you: 3572 2389 3584 3293 idea: It is to insert a blank space from the left, from 1 ~ N use a line segment tree to record their locations, and then perform LIS on their locations. 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];printf("%d\n",len);}printf("\n");}}


 

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.