zoukankan      html  css  js  c++  java
  • P4309 [TJOI2013]最长上升子序列

    题目

    P4309 [TJOI2013]最长上升子序列

    做法

    最长上升序列的求法肯定是烂大街了

    水题是肯定的,确定出序列的位置然后套个树状数组就好了(强制在线的话改成线段树维护前缀最值也行)

    所以说这题其实难点在与怎么让代码简洁,见识到一个新的(STL)(rope)

    My complete code

    #include<bits/stdc++.h>
    #include<ext/rope>
    using namespace std;
    typedef int LL;
    const LL maxn=1e6;
    __gnu_cxx:: rope<LL> a;
    LL n;
    LL tree[maxn],ans[maxn];
    inline LL Lowbit(LL x){ return x&(-x); }
    inline LL Query(LL x){
    	LL ret(0);
    	for(;x;x-=Lowbit(x)) ret=max(ret,tree[x]);
    	return ret;
    }
    inline void Modify(LL x,LL val){
    	for(;x<=n;x+=Lowbit(x))
    	    tree[x]=max(tree[x],val);
    }
    int main(){
    	cin>>n;
    	for(LL i=1;i<=n;++i){
    		LL p; cin>>p;
    		a.insert(p,i);
    	}
    	for(LL i=0;i<n;++i){
    		LL num=a[i];
    		ans[num]=Query(num-1)+1;
    		Modify(num,ans[num]);
    	}
    	for(LL i=1;i<=n;++i){
    		ans[i]=max(ans[i],ans[i-1]);
    		cout<<ans[i]<<endl;
    	}return 0;
    } 
    
  • 相关阅读:
    Linux pmap 工具
    bzoj 1060 贪心
    bzoj 1076 状压DP
    bzoj 1150 贪心
    bzoj 1412 最小割 网络流
    bzoj 3212 线段树
    bzoj 1942 斜率优化DP
    bzoj 1876 高精
    bzoj 1880 最短路
    斜率优化DP讲解
  • 原文地址:https://www.cnblogs.com/y2823774827y/p/10353312.html
Copyright © 2011-2022 走看看