zoukankan      html  css  js  c++  java
  • [BZOJ3262]陌上花开(CDQ分治)

    经典的三位偏序经(mo)典(ban)题,

    一维排序,二维CDQ分治,3维BIT

    Code

    #include <cstdio>
    #include <algorithm>
    #define lowbit(x) ((x)&(-x))
    #define N 100010
    using namespace std;
    
    inline int read(){
        int x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    
    struct flower{
    	int a,b,c,w,s;
    	flower(){a=b=c=w=s=0;}
    	friend bool operator <(flower x,flower y){
    		return (x.a==y.a&&x.b==y.b)?(x.c<y.c):((x.a==y.a)?x.b<y.b:x.a<y.a);
    	}
    	friend bool operator ==(flower x,flower y){
    		return (x.a==y.a&&x.b==y.b&&x.c==y.c);
    	}
    	void rd(){a=read(),b=read(),c=read(),w=1;}
    }A[N],tmp[N];
    int n,mx,na,T[N*2],Ans[N];
    
    inline void Init(){
    	n=read(),mx=read();
    	for(int i=1;i<=n;A[i++].rd());
    	sort(A+1,A+n+1);
    	int p=1;
    	for(int i=2;i<=n;++i) if(A[i]==A[p]) A[p].w++;else A[++p]=A[i];//去重
    	na=n,n=p;	
    }
    
    void add(int x,int v){for(;x<=mx;x+=lowbit(x)) T[x]+=v;}
    int sum(int x){int r=0;for(;x;x-=lowbit(x)) r+=T[x];return r;}
    
    inline void solve(int l,int r){
    	if(l==r) return;
    	int m=(l+r)>>1;
    	solve(l,m),solve(m+1,r);
    	int p=l,q=m+1,cnt=l;
    	while(p<=m||q<=r)
    		if(q>r||(p<=m&&A[p].b<=A[q].b)) add(A[p].c,A[p].w),tmp[cnt++]=A[p++];
    		else A[q].s+=sum(A[q].c),tmp[cnt++]=A[q++];
    	for(int i=l;i<=m;++i) add(A[i].c,-A[i].w);//清空BIT
    	for(int i=l;i<=r;++i) A[i]=tmp[i];
    }
    
    int main(){
    	Init();
    	solve(1,n);
    	for(int i=1;i<=n;++i) Ans[A[i].s+A[i].w-1]+=A[i].w;
    	for(int i=0;i<na;printf("%d
    ",Ans[i++]));
    	return 0;
    }
    
  • 相关阅读:
    用AVIFile函数制做AVI文件基本步骤
    RHEL5下源码安装Mysql
    RHEL 6.2/i686配置使用CentOS YUM源
    教你选择最稳定的 MySQL 版本
    RHEL 6.2/i686桌面版解决风扇狂转的问题 安装官方闭源ATI显卡驱动
    Ubuntu 11.10下解决JUK播放MP3乱码的方法
    Ubuntu 10.04下SVN+Apache安装、配置与使用
    Ubuntu 11.10安装(卸载)ATI闭源驱动导致黑屏进不了系统的解决办法
    ubuntu 11.10下创建eclipse桌面快捷方式
    Ubuntu 11.10与Windows双系统的硬盘安装方法
  • 原文地址:https://www.cnblogs.com/void-f/p/9081157.html
Copyright © 2011-2022 走看看