设为首页 加入收藏

TOP

HDU3564Another LIS(线段树,LIS升级)
2015-07-20 17:40:58 来源: 作者: 【 】 浏览:2
Tags:HDU3564Another LIS 线段 升级

Another LIS

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1211 Accepted Submission(s): 424


Problem Description There 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.
Input An 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.

Output For 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
1
3
0 0 2

Sample Output
Case #1:
1
1
2

Hint
In the sample, we add three numbers to the sequence, and form three sequences.
a. 1
b. 2 1
c. 2 1 3
 

Author standy
Source 2010 ACM-ICPC Multi-University Training Contest(13)――Host by UESTC 解题:先求出这个序列+排序+LIS。
#include
  
   
#include
   
     #include
    
      using namespace std; #define N 100100 typedef struct nnn { int id,i; }point; int tree[3*N]; point oder[N]; void bulide1(int l,int r,int k) { tree[k]=r-l+1; if(l==r)return ; bulide1(l,(l+r)/2,k*2); bulide1((l+r)/2+1,r,k*2+1); } void set_tree1(int l,int r,int k,int id,int i) { int m=(l+r)/2; tree[k]--; if(l==r) { oder[l].id=l; oder[l].i=i; return ; } if(tree[k*2]>=id)set_tree1(l,m,k*2,id,i); else set_tree1(m+1,r,k*2+1,id-tree[k*2],i); } bool cmp(point a,point b){return a.i
     
      tree[k*2+1]) tree[k]=tree[k*2]; else tree[k]=tree[k*2+1]; } int query2(int l,int r,int k,int id) { int m=(l+r)/2; if(l==r)return 0; int max=0; if(m>=id) max=query2(l,m,k*2,id); else { max=query2(m+1,r,k*2+1,id); if(max
      
       0;i--) set_tree1(1,n,1,a[i],i); sort(oder+1,oder+n+1,cmp); bulide2(1,n,1); for(int i=1;i<=n;i++) { int lis=1+query2(1,n,1,oder[i].id); set_tree2(1,n,1,oder[i].id,lis); LIS[i]=tree[1]; } printf("Case #%d:\n",j); for(int i=1;i<=n;i++) printf("%d\n",LIS[i]); printf("\n"); } } 
      
     
    
   
  

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Effective STL: 将vector和string.. 下一篇hdu 5012 Dice

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·用 C 语言或者限制使 (2025-12-25 08:50:05)
·C++构造shared_ptr为 (2025-12-25 08:50:01)
·既然引用计数在做 GC (2025-12-25 08:49:59)
·Java 编程和 c 语言 (2025-12-25 08:19:48)
·. net内存管理宝典这 (2025-12-25 08:19:46)