# 【刷题】BZOJ 3262 陌上花开

10 3
3 3 3
2 3 3
2 3 1
3 1 1
3 1 2
1 3 1
1 1 2
1 2 2
1 3 2
1 2 1

3
1
3
0
1
0
1
0
0
1

## Solution

#include<bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define Mid ((l+r)>>1)
const int MAXN=200000+10,MAXM=300000+10,base=233,Mod=1e9+7;
int n,m,ans[MAXN];
struct node{
int x,y,z,ans,w;
inline bool operator == (const node &A) const {
return x==A.x&&y==A.y&&z==A.z;
};
};
node point[MAXN],tmp[MAXN];
struct BIT{
int C[MAXM];
inline void init()
{
memset(C,0,sizeof(C));
}
inline int lowbit(int x)
{
return x&(-x);
}
inline void add(int x,int k)
{
while(x<=m)
{
C[x]+=k;
x+=lowbit(x);
}
}
inline int sum(int x)
{
int res=0;
while(x)
{
res+=C[x];
x-=lowbit(x);
}
return res;
}
};
BIT T;
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char c='\0')
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
if(c!='\0')putchar(c);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline bool cmp1(node a,node b)
{
return a.x<b.x||(a.x==b.x&&a.y<b.y)||(a.x==b.x&&a.y==b.y&&a.z<b.z);
}
inline bool cmp2(node a,node b)
{
return a.y<b.y||(a.y==b.y&&a.z<b.z);
}
inline void CDQ(int l,int r)
{
if(l==r)return ;
CDQ(l,Mid);CDQ(Mid+1,r);
std::sort(point+l,point+Mid+1,cmp2);
std::sort(point+Mid+1,point+r+1,cmp2);
int j=l;
for(register int i=Mid+1;i<=r;++i)
{
while(point[j].y<=point[i].y&&j<=Mid)T.add(point[j].z,point[j].w),++j;
point[i].ans+=T.sum(point[i].z);
}
for(register int i=l;i<j;++i)T.add(point[i].z,-point[i].w);
}
int main()
{
read(n);read(m);
for(register int i=1;i<=n;++i)read(tmp[i].x),read(tmp[i].y),read(tmp[i].z);
std::sort(tmp+1,tmp+n+1,cmp1);
int pn=0;
for(register int i=1,now=1;i<=n;++i,++now)
if(!(tmp[i]==tmp[i+1]))point[++pn]=tmp[i],point[pn].w=now,now=0;
T.init();
CDQ(1,pn);
for(register int i=1;i<=pn;++i)ans[point[i].ans+point[i].w-1]+=point[i].w;
for(register int i=0;i<n;++i)write(ans[i],'\n');
return 0;
}

posted @ 2018-03-28 21:25  HYJ_cnyali  阅读(117)  评论(0编辑  收藏  举报