cdq

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=200105;
int n,m,c[N],dp[N],T,k,ans[N];
struct node
{
int x,y,z,id;
}a[N],tmp[N];
struct Tree
{
int c[N];
inline int low(int x){return x&-x;}
inline void modify(int x){while (x<=N-100)c[x]=0,x+=low(x);}
inline void updata(int x){while (x<=N-100)c[x]++,x+=low(x);}
inline void init(){memset(c,0,sizeof c);}
inline int query(int x)
{
int ans=0;
while (x)ans+=c[x],x-=low(x);
return ans;
}
}Tree;
inline int cmp(node x,node y)
{
if (x.x!=y.x)return x.x<y.x;
if (x.y!=y.y)return x.y<y.y;
return x.z<y.z;
}
inline int cmp1(node x,node y)
{
if (x.y!=y.y)return x.y<y.y;
return x.z<y.z;
}
inline void solve(int l,int r)
{
if (l==r)return;
int m=(l+r)>>1;
solve(l,m);
for (int i=l;i<=r;i++)tmp[i]=a[i];
sort(tmp+l,tmp+m+1,cmp1);
sort(tmp+m+1,tmp+r+1,cmp1);
int pl=l;
for (int i=m+1;i<=r;i++)
{
while (pl<=m&&tmp[pl].y<=tmp[i].y)
{
Tree.updata(tmp[pl].z);
pl++;
}
dp[tmp[i].id]+=Tree.query(tmp[i].z);
}
for (int i=l;i<=m;i++)Tree.modify(tmp[i].z);
solve(m+1,r);
}
int main()
{
scanf("%d%d",&n,&k);
for (int i=1;i<=n;i++)
{
scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
a[i].id=i;
}
sort(a+1,a+n+1,cmp);
memset(dp,0,sizeof dp);
Tree.init();
solve(1,n);
for (int i=n-1;i;i--)
if (a[i].x==a[i+1].x&&a[i].y==a[i+1].y&&a[i].z==a[i+1].z)dp[a[i].id]=dp[a[i+1].id];
for (int i=1;i<=n;i++)ans[dp[i]]++;
for (int i=0;i<n;i++)printf("%d\n",ans[i]);
}

posted on 2018-02-06 21:10  宣毅鸣  阅读(77)  评论(0编辑  收藏  举报