对第一关键字排序,分治每朵花,合并的时候通过归并左右的花的第二关键字,将值插入树状数组中求值。对于相同的花,先进行预处理即可。
#include"bits/stdc++.h"
#define lowbit(x) ((x)&-(x))
using namespace std;
const int N=100005,M=200005;
int n,m;
int sum[M];
inline void add(int x,int op){for(;x<=m;x+=lowbit(x))sum[x]+=op;}
inline int qry(int to){int re=0;for(;to>=1;to-=lowbit(to))re+=sum[to];return re;}
int x[N],y[N],z[N],id[N],ans[N],res[N];
inline bool cmp(const int&a,const int&b){return x[a]<x[b]||x[a]==x[b]&&y[a]<y[b]||x[a]==x[b]&&y[a]==y[b]&&z[a]<z[b];}
void solve(int l,int r){
int mid=(l+r)>>1,i,j;if(l==r)return;
solve(l,mid);solve(mid+1,r);
for(i=l,j=mid+1;j<=r;j++){
while(i<=mid&&y[id[i]]<=y[id[j]])add(z[id[i]],1),i++;
ans[id[j]]+=qry(z[id[j]]);
}
while(i>l)add(z[id[--i]],-1);
static int ms[N],tmp;tmp=l-1;
for(i=l,j=mid+1;i<=mid||j<=r;){
if(i>mid) ms[++tmp]=id[j++];
else if(j>r||y[id[i]]<y[id[j]]) ms[++tmp]=id[i++];
else ms[++tmp]=id[j++];
}
memcpy(id+l,ms+l,sizeof(int)*(r-l+1));
}
int main(){
scanf("%d%d",&n,&m);int i,j,k;
for(i=1;i<=n;i++)id[i]=i,scanf("%d%d%d",&x[i],&y[i],&z[i]);
sort(id+1,id+n+1,cmp);
for(i=j=1;i<=n;i=++j){
while(!(cmp(id[j],id[j+1])|cmp(id[j+1],id[j])))j++;
for(k=i;k<=j;k++)ans[id[k]]+=j-k;
}solve(1,n);
for(i=1;i<=n;i++)res[ans[i]]++;
for(i=0;i<n;i++)printf("%d\n",res[i]);
return 0;
}