标签:ted seq ecif title show can auto orm sequence
1 3 0 0 2
Case #1: 1 1 2HintIn the sample, we add three numbers to the sequence, and form three sequences. a. 1 b. 2 1 c. 2 1 3
#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; else r=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); } else insert(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"); } }
HDOJ 题目3564 Another LIS(线段树单点更新,LIS)
标签:ted seq ecif title show can auto orm sequence
原文地址:http://www.cnblogs.com/lxjshuju/p/6848353.html