zoukankan      html  css  js  c++  java
  • luogu4093 [HEOI2016/TJOI2016]序列

    因为一个变化只会变化一个值,所以
    (dp[i]=max(dp[j])+1,j<i,maxval_j leq a[i], a[j] leq minval_i)
    发现跟二维数点问题挺像,树状数组套线段树爽一爽。

    #include <iostream>
    #include <cstdio> 
    using namespace std;
    int n, m, zdz[100005], zxz[100005], a[100005], uu, vv, cnt, dp[100005], ans, rot[100005];
    struct Node{
    	int l, r, zdz;
    }nd[9000005];
    int lb(int x){
    	return x&-x;
    }
    void insert(int &o, int l, int r, int x, int k){
    	if(!o)	o = ++cnt;
    	if(l==r)	nd[o].zdz = max(nd[o].zdz, k);
    	else{
    		int mid=(l+r)>>1;
    		if(x<=mid)	insert(nd[o].l, l, mid, x, k);
    		if(mid<x)	insert(nd[o].r, mid+1, r, x, k);
    		nd[o].zdz = max(nd[nd[o].l].zdz, nd[nd[o].r].zdz);
    	}
    }
    int query(int o, int l, int r, int x, int y){
    	if(!o)	return 0;
    	if(l>=x &&r<=y)	return nd[o].zdz;
    	else{
    		int mid=(l+r)>>1;
    		int re=0;
    		if(x<=mid)	re = max(re, query(nd[o].l, l, mid, x, y));
    		if(mid<y)	re = max(re, query(nd[o].r, mid+1, r, x, y));
    		return re;
    	}
    }
    int main(){
    	cin>>n>>m;
    	for(int i=1; i<=n; i++){
    		scanf("%d", &a[i]);
    		zdz[i] = zxz[i] = a[i];
    	}
    	for(int i=1; i<=m; i++){
    		scanf("%d %d", &uu, &vv);
    		zdz[uu] = max(zdz[uu], vv);
    		zxz[uu] = min(zxz[uu], vv);
    	}
    	for(int i=1; i<=n; i++){
    		for(int j=zxz[i]; j; j-=lb(j))
    			dp[i] = max(dp[i], query(rot[j], 1, 100000, 1, a[i]));
    		dp[i]++;
    		ans = max(ans, dp[i]);
    		for(int j=a[i]; j<=100000; j+=lb(j))
    			insert(rot[j], 1, 100000, zdz[i], dp[i]);
    	}
    	cout<<ans<<endl;
    	return 0;
    }
    
  • 相关阅读:
    Java中RuntimeException和Exception
    RuntimeException和Exception的区别
    Spring事务异常回滚
    iOS 卖票中多线程分析;
    凝视转换(部分)
    HDU 5386 Cover(模拟)
    iOS开发之软键盘使用小技巧
    【每日算法】高速幂
    CKEditor高级编辑器
    iOS开发 剖析网易新闻标签栏视图切换(addChildViewController属性介绍)
  • 原文地址:https://www.cnblogs.com/poorpool/p/8446767.html
Copyright © 2011-2022 走看看