【spoj】Another Longest Increasing Subsequence Problem cdq分治
来源:互联网 发布:线切割编程例子 编辑:程序博客网 时间:2024/06/05 01:08
没什么好说的就是写了两个版
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#define maxn 500021using namespace std;int n,ans[maxn],c[maxn*4],t[maxn],cnt;struct node{int x,y,id;bool operator<(const node& b)const{return id<b.id;}}q[maxn],p[maxn];bool cmp(const node& a,const node& b){return a.x<b.x;}void update(int x,int add){while(x<=cnt){if(add>0)c[x]=max(c[x],add);else c[x]=0;x+=x&-x;}}int query(int x){int ans=0;while(x>0){ans=max(ans,c[x]);x-=x&-x;}return ans;}void solve(int l,int r){if(l>=r)return;int mid=l+r>>1;solve(l,mid);sort(q+l,q+r+1,cmp);for(int j,i=l;i<=r;i=j){for(j=i+1;j<=r;j++)if(q[j].x!=q[j-1].x)break;for(int k=i;k<j;k++)if(q[k].id>mid)ans[q[k].id]=max(ans[q[k].id],query(q[k].y-1)+1);for(int k=i;k<j;k++)if(q[k].id<=mid)update(q[k].y,ans[q[k].id]);}for(int i=l;i<=r;i++)if(q[i].id<=mid)update(q[i].y,-1);sort(q+l,q+r+1);solve(mid+1,r);}/*void solve(int l,int r){if(l >= r) return;int mid = (l+r)>>1;solve(l,mid);sort(q+l,q+1+mid,cmp);sort(q+mid+1,q+r+1,cmp);int j = l;for(int i = mid+1; i <= r; i++){for(; j <= mid && q[j].x < q[i].x; j++) update(q[j].y, ans[q[j].id]);ans[q[i].id] = max(ans[q[i].id], query(q[i].y-1)+1);}for(int i = l; i <= mid; i++) update(q[i].y,-1);sort(q+mid+1,q+r+1);solve(mid+1,r);}*/int main(){scanf("%d",&n);for(int i=1;i<=n;i++){ans[i]=1,q[i].id=i;scanf("%d%d",&q[i].x,&q[i].y);t[++cnt]=q[i].y;}sort(t+1,t+1+cnt);cnt=unique(t+1,t+1+cnt)-t-1;for(int i=1;i<=n;i++){q[i].y=lower_bound(t+1,t+1+cnt,q[i].y)-t;}solve(1,n);int Ans=0;for(int i=1;i<=n;i++)Ans=max(Ans,ans[i]);printf("%d",Ans);return 0;}
0 0
- 【spoj】Another Longest Increasing Subsequence Problem cdq分治
- SPOJ LIS2 Another Longest Increasing Subsequence Problem 三维偏序最长链 CDQ分治
- SPOJ LIS2 (Another Longest Increasing Subsequence Problem) CDQ求三维偏序+离散化+LIS
- SPOJ-LIS2 Another Longest Increasing Subsequence Problem 【三维偏序CDQ】
- BZOJ 2225: [Spoj 2371]Another Longest Increasing CDQ
- 【BZOJ】【P2225】【Spoj 2371】【Another Longest Increasing】【树套树】
- Longest Increasing Subsequence
- 【DP】 Longest Increasing Subsequence
- Longest Increasing Subsequence(LIS)
- Longest Increasing Subsequence
- 【算法】Longest Increasing Subsequence
- Longest Increasing Subsequence
- Longest Increasing Subsequence
- Longest Increasing Subsequence
- Longest Increasing Subsequence
- Longest Increasing Subsequence(LIS)
- Longest Increasing Subsequence
- [DP]Longest Increasing Subsequence
- codeforces 149D Coloring Brackets 区间DP
- Avoiding getting banned(Scrapy)
- 如何理解<base href="<%=basePath%>"
- 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC。 是否AC的规则如下: 1. zoj能AC; 2. 若字符串形式为xzojx,则也能AC,其中x可以是N个'o' 或者为空;
- <hadoop> mapreduce程序分块
- 【spoj】Another Longest Increasing Subsequence Problem cdq分治
- Larave5.*框架 数据库的CURD增删改查操作教程
- Android Studio 生成签名apk
- UVA 861 Little Bishops 组合数学
- 456456456
- 面试感悟----一名3年工作经验的程序员应该具备的技能
- 如果爱
- Octave 命令积累
- error: 'NULL' was not declared in this scope