传送门

CJOJ

Solution

具体实现参考上一篇Blog(四维偏序)

代码实现1(cdq+cdq+cdq+BIT)

/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi()
{
    int f=1,sum=0;char ch=getchar();
    while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
const int N=50010;
struct node
{
    int opt1,opt2,a,b,c,d;
}a[N],tmp1[N],tmp2[N],tmp3[N];
int c[N],n,tot,ans;
int lowbit(int x){return x&(-x);}
void Add(int x,int d){while(x<=n){c[x]+=d;x+=lowbit(x);}}
int query(int x){int ret=0;while(x){ret+=c[x];x-=lowbit(x);}return ret;}
void cdq1(int,int);
void cdq2(int,int);
void cdq3(int,int);
int main()
{
    n=gi();
    for(int i=1;i<=n;i++)a[i].a=gi();
    for(int i=1;i<=n;i++)a[i].b=gi();
    for(int i=1;i<=n;i++)a[i].c=gi();
    for(int i=1;i<=n;i++)a[i].d=gi();
    cdq1(1,n);
    printf("%d\n",ans);
    return 0;
}
void cdq1(int l,int r)
{
    if(l==r)return;
    int mid=(l+r)>>1;
    cdq1(l,mid);cdq1(mid+1,r);
    int L=l,R=mid+1;tot=l-1;
    while(L<=mid && R<=r)
    {
        if(a[L].a<a[R].a){a[L].opt1=0;tmp1[++tot]=a[L++];}
        else{a[R].opt1=1;tmp1[++tot]=a[R++];}
    }
    while(L<=mid){a[L].opt1=0;tmp1[++tot]=a[L++];}
    while(R<=r){a[R].opt1=1;tmp1[++tot]=a[R++];}
    for(int i=l;i<=r;i++)a[i]=tmp1[i];
    cdq2(l,r);
}
void cdq2(int l,int r)
{
    if(l==r)return;
    int mid=(l+r)>>1;
    cdq2(l,mid);cdq2(mid+1,r);
    int L=l,R=mid+1;tot=l-1;
    while(L<=mid && R<=r)
    {
        if(tmp1[L].b<tmp1[R].b){tmp1[L].opt2=0;tmp2[++tot]=tmp1[L++];}
        else{tmp1[R].opt2=1;tmp2[++tot]=tmp1[R++];}
    }
    while(L<=mid){tmp1[L].opt2=0;tmp2[++tot]=tmp1[L++];}
    while(R<=r){tmp1[R].opt2=1;tmp2[++tot]=tmp1[R++];}
    for(int i=l;i<=r;i++)tmp1[i]=tmp2[i];
    cdq3(l,r);
}
void cdq3(int l,int r)
{
    if(l==r)return;
    int mid=(l+r)>>1;
    cdq3(l,mid);cdq3(mid+1,r);
    int L=l,R=mid+1;tot=l-1;
    while(L<=mid && R<=r)
    {
        if(tmp2[L].c<tmp2[R].c)
        {
            tmp3[++tot]=tmp2[L];
            if(!tmp2[L].opt1 && !tmp2[L].opt2)Add(tmp2[L].d,1);
            L++;
        }
        else
        {
            tmp3[++tot]=tmp2[R];
            if(tmp2[R].opt1 && tmp2[R].opt2)ans+=query(tmp2[R].d);
            R++;
        }
    }
    while(R<=r)
    {
        tmp3[++tot]=tmp2[R];
        if(tmp2[R].opt1 && tmp2[R].opt2)ans+=query(tmp2[R].d);
        R++;
    }
    for(int i=l;i<L;i++)if(!tmp2[i].opt1 && !tmp2[i].opt2)Add(tmp2[i].d,-1);
    while(L<=mid)tmp3[++tot]=tmp2[L++];
    for(int i=l;i<=r;i++)tmp2[i]=tmp3[i];
}

代码实现2(cdq+cdq+cdq+cdq)

/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi()
{
    int f=1,sum=0;char ch=getchar();
    while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
const int N=100010;
struct node
{
    int a,b,c,opt1,opt2,opt3,d;
}a[N<<1],tmp1[N],tmp2[N],tmp3[N],tmp4[N];
int n,ans;
void cdq4(int,int);
void cdq3(int,int);
void cdq2(int,int);
void cdq1(int,int);
int main()
{
    n=gi();
    for(int i=1;i<=n;i++)a[i].a=gi();
    for(int i=1;i<=n;i++)a[i].b=gi();
    for(int i=1;i<=n;i++)a[i].c=gi();
    for(int i=1;i<=n;i++)a[i].d=gi();
    cdq1(1,n);
    printf("%d\n",ans);
    return 0;
}
void cdq1(int l,int r)
{
    if(l==r)return;
    int mid=(l+r)>>1;
    cdq1(l,mid);cdq1(mid+1,r);
    int tot=l-1;int L=l,R=mid+1;
    while(L<=mid && R<=r)
    {
        if(a[L].a<a[R].a){a[L].opt1=0;tmp1[++tot]=a[L++];}
        else{a[R].opt1=1;tmp1[++tot]=a[R++];}
    }
    while(L<=mid){a[L].opt1=0;tmp1[++tot]=a[L++];}
    while(R<=r){a[R].opt1=1;tmp1[++tot]=a[R++];}
    for(int i=l;i<=r;i++)a[i]=tmp1[i];
    cdq2(l,r);
}
void cdq2(int l,int r)
{
    if(l==r)return;
    int mid=(l+r)>>1;
    cdq2(l,mid);cdq2(mid+1,r);
    int tot=l-1;int L=l,R=mid+1;
    while(L<=mid && R<=r)
    {
        if(tmp1[L].b<tmp1[R].b){tmp1[L].opt2=0;tmp2[++tot]=tmp1[L++];}
        else{tmp1[R].opt2=1;tmp2[++tot]=tmp1[R++];}
    }
    while(L<=mid){tmp1[L].opt2=0;tmp2[++tot]=tmp1[L++];}
    while(R<=r){tmp1[R].opt2=1;tmp2[++tot]=tmp1[R++];}
    for(int i=l;i<=r;i++)tmp1[i]=tmp2[i];
    cdq3(l,r);
}
void cdq3(int l,int r)
{
    if(l==r)return;
    int mid=(l+r)>>1;
    cdq3(l,mid);cdq3(mid+1,r);
    int tot=l-1;int L=l,R=mid+1;
    while(L<=mid && R<=r)
    {
        if(tmp2[L].c<tmp2[R].c){tmp2[L].opt3=0;tmp3[++tot]=tmp2[L++];}
        else{tmp2[R].opt3=1;tmp3[++tot]=tmp2[R++];}
    }
    while(L<=mid){tmp2[L].opt3=0;tmp3[++tot]=tmp2[L++];}
    while(R<=r){tmp2[R].opt3=1;tmp3[++tot]=tmp2[R++];}
    for(int i=l;i<=r;i++)tmp2[i]=tmp3[i];
    cdq4(l,r);
}
void cdq4(int l,int r)
{
    if(l==r)return;
    int mid=(l+r)>>1;
    cdq4(l,mid);cdq4(mid+1,r);
    int tot=l-1;int L=l,R=mid+1,cnt=0;
    while(L<=mid && R<=r)
    {
        if(tmp3[L].d<tmp3[R].d){if((tmp3[L].opt1|tmp3[L].opt2|tmp3[L].opt3)==0)cnt++;tmp4[++tot]=tmp3[L++];}
        else{if((tmp3[R].opt1&tmp3[R].opt2&tmp3[R].opt3)==1)ans+=cnt;tmp4[++tot]=tmp3[R++];}
    }
    while(R<=r){if((tmp3[R].opt1&tmp3[R].opt2&tmp3[R].opt3)==1)ans+=cnt;tmp4[++tot]=tmp3[R++];}
    while(L<=mid)tmp4[++tot]=tmp3[L++];
    for(int i=l;i<=r;i++)tmp3[i]=tmp4[i];
}

【CJOJ2375】 【HZOI 2015】偏序 II(cdq分治,树状数组)的更多相关文章

  1. LOJ3146 APIO2019路灯(cdq分治+树状数组)

    每个时刻都形成若干段满足段内任意两点可达.将其视为若干正方形.则查询相当于求历史上某点被正方形包含的时刻数量.并且注意到每个时刻只有O(1)个正方形出现或消失,那么求出每个矩形的出现时间和消失时间,就 ...

  2. 【BZOJ4553】[Tjoi2016&Heoi2016]序列 cdq分治+树状数组

    [BZOJ4553][Tjoi2016&Heoi2016]序列 Description 佳媛姐姐过生日的时候,她的小伙伴从某宝上买了一个有趣的玩具送给他.玩具上有一个数列,数列中某些项的值可能 ...

  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. BZOJ 1176 Mokia CDQ分治+树状数组

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 1854  Solved: 821[Submit][St ...

  5. 【bzoj3262】陌上花开 CDQ分治+树状数组

    题目描述 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当且仅当Sa&g ...

  6. BZOJ 2683 简单题 cdq分治+树状数组

    题意:链接 **方法:**cdq分治+树状数组 解析: 首先对于这道题,看了范围之后.二维的数据结构是显然不能过的.于是我们可能会考虑把一维排序之后还有一位上数据结构什么的,然而cdq分治却可以非常好 ...

  7. bzoj 3262 陌上花开 - CDQ分治 - 树状数组

    Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当 ...

  8. BZOJ 4553 [Tjoi2016&Heoi2016]序列 ——CDQ分治 树状数组

    考虑答案的构成,发现是一个有限制条件的偏序问题. 然后三个维度的DP,可以排序.CDQ.树状数组各解决一维. #include <map> #include <cmath> # ...

  9. BZOJ3262陌上花开(三维偏序问题(CDQ分治+树状数组))+CDQ分治基本思想

    emmmm我能怎么说呢 CDQ分治显然我没法写一篇完整的优秀的博客,因为我自己还不是很明白... 因为这玩意的思想实在是太短了: fateice如是说道: 如果说对于一道题目的离线操作,假设有n个操作 ...

  10. hdu_4742_Pinball Game 3D(cdq分治+树状数组)

    题目链接:hdu_4742_Pinball Game 3D 题意: 给你n个点,让你求三维的LIS,并且求出有多少种组合能达到LIS. 题解: 求三维的LIS,典型的三维偏序问题,x排序,解决一维,c ...

随机推荐

  1. centOS 6.5下升级mysql,从5.1升级到5.6

    转载:https://www.cnblogs.com/vickygu2007/p/5066409.html #mysqldump -uroot -p --all-databases > data ...

  2. myeclipse 上安装 Maven3

    myeclipse 上安装 Maven3   环境准备: JDK 1.6 Maven 3.0.4 myeclipse 8.6.1 安装 Maven 之前要求先确定你的 JDK 已经安装配置完成.Mav ...

  3. Windows-universal-samples学习笔记系列五:Custom user interactions

    Custom user interactions Basic input Complex inking Inking Low latency input Simple inking Touch key ...

  4. unity延时函数

    新建一个工具类 public class DelayToInvoke : MonoBehaviour{ public static IEnumerator DelayToInvokeDo(Action ...

  5. 2018.11.24 poj2774Long Long Message(后缀数组)

    传送门 实际上可以用后缀自动机秒掉 当然后缀数组也挺好写. 我们将两个字符串接在一起,为了方便中间用一个特殊字符连接. 然后对新字符串求heightheightheight数组. 求出来之后对所有满足 ...

  6. 注意JDBC驱动的版本和JDK的版本是否匹配 JDBC连接Mariadb

    Java利用JDBC连接Mariadb的过程和MySQL基本一致. 但是需要注意JDBC驱动的版本和JDK的版本是否匹配: JDBC和JDK版本对应关系 JDBC版本 JDK版本 2.x 1.8 1. ...

  7. top k问题

    1.top k问题 在海量数据处理中,经常会遇到的一类问题:在海量数据中找出出现频率最高的前k个数,或者从海量数据中找出最大的前k个数,这类问题通常被称为top K问题.例如,在搜索引擎中,统计搜索最 ...

  8. eclipse 创建servlet 出现继承 HttpServlet 报红线

    eclipse创建servlet出现红线: 解决方案1,鼠标右键项目 -> 鼠标右击项目——>Build Path——> 点击comfigure Build Path进入-----& ...

  9. SVN被锁定的几种解决方法

    用SVN经常出现被锁定而无法提交的问题,选择解锁又提示没有文件被锁定,很是头疼.这里整理了一下SVN被锁定的几种解决方法: 1.出现这个问题后使用“清理”即"Clean up"功能 ...

  10. Gym 100096D Guessing game

    Gym 100096D Guessing game 题面 Problem Description Byteman is playing a following game with Bitman. Bi ...