这道题 连续上升的三元组 且已经按照第一维排好序了。

直接上CDQ分治即可 当然也是可以2-Dtree解决这个 问题 但是感觉nlog^2 比nsqrt(n)要快一些。。

算是复习一发CDQ分治吧 也好久没写了。

原来最长三元上升序列 不是裸的CDQ分治。。我以为是 没细想 最后还是细想了一下实现方式。

首先CDQ左边 然后对于右边此时x是无序的 考虑排序 在外面排序没用好吧。。

好吧可能有用但是太过繁琐那种写法 这里推荐暴力sort。。归并没用 因为归并此时复杂度还是nlogn的。

统计完左边对右边的贡献后 再桶排序复原。再CDQ右边 回来的时候可以进行归并不需要再sort了节省常数。。

复杂度nlog^2。

const int MAXN=100010;
int n,top,ans;
struct wy
{
int x,y;
int id;
inline int friend operator <(wy a,wy b){return a.x==b.x?a.id<b.id:a.x<b.x;}
}t[MAXN],ql[MAXN];
int b[MAXN],f[MAXN],c[MAXN];
inline void discrete()
{
sort(b+1,b+1+n);
rep(1,n,i)if(i==1||b[i]!=b[i-1])b[++top]=b[i];
rep(1,n,i)y(i)=lower_bound(b+1,b+1+top,y(i))-b;
}
inline void add(int x,int y)
{
if(y==-1)
{
while(x<=top)
{
c[x]=0;
x+=x&(-x);
}
return;
}
while(x<=top)
{
c[x]=max(c[x],y);
x+=x&(-x);
}
}
inline int ask(int x)
{
int cnt=0;
while(x)
{
cnt=max(cnt,c[x]);
x-=x&(-x);
}
return cnt;
}
inline void CDQ(int l,int r)
{
if(l==r){++f[id(l)];return;}
int mid=(l+r)>>1;
CDQ(l,mid);
sort(t+mid+1,t+r+1);
int i=l,j=mid+1;
for(int k=l;k<=r+1;++k)
{
if(j>r)
{
for(int w=i-1;w>=l;--w)add(y(w),-1);
break;
}
if((i<=mid)&&x(i)<x(j))add(y(i),f[id(i)]),++i;
else f[id(j)]=max(f[id(j)],ask(y(j)-1)),++j;
}
for(int k=mid+1;k<=r;++k)ql[id(k)]=t[k];
for(int k=mid+1;k<=r;++k)t[k]=ql[k];
CDQ(mid+1,r);
i=l;j=mid+1;
for(int k=l;k<=r;++k)
{
if(i<=mid&&x(i)<x(j)||j>r)ql[k]=t[i],++i;
else ql[k]=t[j],++j;
}
for(int k=l;k<=r;++k)t[k]=ql[k];
}
int main()
{
freopen("1.in","r",stdin);
get(n);
rep(1,n,i)get(x(i)),b[i]=get(y(i)),id(i)=i;
discrete();
CDQ(1,n);
for(int i=1;i<=n;++i)ans=max(ans,f[i]);
printf("%d\n",ans);
return 0;
}

这个树状数组清空的时候注意不要暴力清空 再来一遍序列 清成0即可。

bzoj 2225 [Spoj 2371]Another Longest Increasing的更多相关文章

  1. BZOJ 2225 [Spoj 2371]Another Longest Increasing(CDQ分治)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2225 [题目大意] 给定N个数对(xi,yi),求最长上升子序列的长度. 上升序列定义 ...

  2. BZOJ 2225: [Spoj 2371]Another Longest Increasing (CDQ分治+dp)

    题面 Description 给定N个数对(xi, yi),求最长上升子序列的长度.上升序列定义为{(xi, yi)}满足对i<j有xi<xj且yi<yj. Input Output ...

  3. 【bzoj2225】[Spoj 2371]Another Longest Increasing CDQ分治+树状数组

    题目描述 给定N个数对(xi, yi),求最长上升子序列的长度.上升序列定义为{(xi, yi)}满足对i<j有xi<xj且yi<yj. 样例输入 8 1 3 3 2 1 1 4 5 ...

  4. BZOJ2225: [Spoj 2371]Another Longest Increasing CDQ分治,3维LIS

    Code: #include <cstdio> #include <algorithm> #include <cstring> #define maxn 20000 ...

  5. BZOJ_2225_[Spoj 2371]Another Longest Increasing_CDQ 分治+树状数组

    BZOJ_2225_[Spoj 2371]Another Longest Increasing_CDQ 分治+树状数组 Description        给定N个数对(xi, yi),求最长上升子 ...

  6. SPOJ LIS2 Another Longest Increasing Subsequence Problem 三维偏序最长链 CDQ分治

    Another Longest Increasing Subsequence Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://a ...

  7. SPOJ - LIS2 Another Longest Increasing Subsequence Problem

    cdq分治,dp(i)表示以i为结尾的最长LIS,那么dp的递推是依赖于左边的. 因此在分治的时候需要利用左边的子问题来递推右边. (345ms? 区间树TLE /****************** ...

  8. SPOJ LIS2 - Another Longest Increasing Subsequence Problem(CDQ分治优化DP)

    题目链接  LIS2 经典的三维偏序问题. 考虑$cdq$分治. 不过这题的顺序应该是 $cdq(l, mid)$ $solve(l, r)$ $cdq(mid+1, r)$ 因为有个$DP$. #i ...

  9. SPOJ Another Longest Increasing Subsequence Problem 三维最长链

    SPOJ Another Longest Increasing Subsequence Problem 传送门:https://www.spoj.com/problems/LIS2/en/ 题意: 给 ...

随机推荐

  1. USACO07NOV Cow Relays G 题解

    题目 For their physical fitness program, \(N (2 ≤ N ≤ 1,000,000)\) cows have decided to run a relay ra ...

  2. Virtual DOM 真的比操作原生 DOM 快吗?

    附上尤大的回答链接链接:https://www.zhihu.com/question/31809713/answer/53544875

  3. 微信小程序热更新,小程序提示版本更新,版本迭代,强制更新,微信小程序版本迭代

    相信很多人在做小程序的时候都会有迭代每当版本迭代的时候之前老版本的一些方法或者显示就不够用了这就需要用到小程序的热更新.或者说是提示升级小程序版本 editionUpdate:function(){ ...

  4. 使用pycharm、跳板机连接内网服务器

    使用pycharm.跳板机连接内网服务器 接手实验室服务器后,大部分同学在GPU集群上跑程序都是直接在ssh界面上跑,这里想着通过pycharm通过跳板机来连接服务器. 总体就是实验室服务器仅限内网访 ...

  5. Python Ethical Hacking - NETWORK_SCANNER(1)

    NETWORK_SCANNER Discover all devices on the network. Display their IP address. Display their MAC add ...

  6. 集训作业 洛谷P1101 单词方阵

    这个题的长度真的有点长,我直接放图片吧 这个题又是一个和谐的搜索,找到yizhong的y就开始8面搜索,遇见正确的字母就继续搜索,不正确就果断放弃,果然又是一个和谐的搜索呢. #include< ...

  7. 【博弈论】Road to Arabella Gym - 102263B

    题目: 题目大意:输入n,k.两个人轮流选一个数x(1<=x<=max(1,n-k))减去n,若到一个人的回合n=0那么那个人失败.Kilani先手. 通过手动模拟几个实例,很容易发现先手 ...

  8. Spring Boot+MyBatis+MySQL读写分离

    读写分离要做的事情就是对于一条sql语句该选择去哪个数据库执行,至于谁来做选择数据库的事情,无非两个,1:中间件(比如MyCat):二:程序自己去做分离操作. 但是从程序成眠去做读写分离最大的弱点就是 ...

  9. php三元运算符?:和??

    1.(expr1) ? (expr2) : (expr3) 在 expr1 求值为 TRUE 时的值为 expr2,在 expr1 求值为 FALSE 时的值为 expr3. $a = (expr1) ...

  10. pandas之groupby分组与pivot_table透视

    一.groupby 类似excel的数据透视表,一般是按照行进行分组,使用方法如下. df.groupby(by=None, axis=0, level=None, as_index=True, so ...