题意:求所有的 x j < x i y j < y i z j < z i ~~x_j<x_i~~y_j<y_i~~z_j<z_i~~ xj<xi yj<yi zj<zi 的 j 的个数
于是,我们就需要用到强大的CDQ分治
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
#define re register
#define gc getchar()
inline int read()
{
re int x(0);re char ch(gc);
while(ch<'0'||ch>'9') ch=gc;
while(ch>='0'&&ch<='9') x=(x*10)+(ch^48),ch=gc;
return x;
}
const int N=2000010;
struct node {int x,y,z,w,id;}a[N];
int n,k,w[N],c[N],sum[N],t[N];
bool cmpx(node a,node b)
{
if(a.x!=b.x) return a.x<b.x;
if(a.y!=b.y) return a.y<b.y;
return a.z<b.z;
}
bool cmpy(node a,node b)
{
if(a.y!=b.y) return a.y<b.y;
if(a.z!=b.z) return a.z<b.z;
return a.x<b.x;
}
int query (int x)
{
int ans=0;
while (x) {
ans+=c[x];
x-=x&-x;
}
return ans;
}
void add (int x,int y)
{
while (x<=k) {
c[x]+=y;
x+=x&-x;
}
}
void cdq(int l,int r)
{
if(l==r) return;
int mid=(l+r)>>1;
cdq(l,mid),cdq(mid+1,r);
sort(a+l,a+mid+1,cmpy);
sort (a+mid+1,a+r+1,cmpy);
int t=l;
for(int i=mid+1;i<=r;++i)
{
while(a[t].y<=a[i].y&&t<=mid)
add(a[t].z,a[t].w),++t;
sum[a[i].id]+=query(a[i].z);
}
for(int i=l;i<t;++i)
add(a[i].z,-a[i].w);
}
int main()
{
n=read(),k=read();
for(int i=1;i<=n;++i)
{
a[i].x=read();
a[i].y=read();
a[i].z=read();
}
sort(a+1,a+1+n,cmpx);
int c=n;n=0;
for(int i=1;i<=c;++i)
{
if(a[i].x!=a[i-1].x||a[i].y!=a[i-1].y||a[i].z!=a[i-1].z)
a[++n]=a[i],a[n].w=1;
else a[n].w++;
}
for(int i=1;i<=n;++i)
a[i].id=i,sum[i]=a[i].w-1;
cdq (1,n);
for (int i=1;i<=n;i++) t[sum[a[i].id]]+=a[i].w;
for (int i=1;i<=c;i++) cout<<t[i-1]<<endl;
return 0;
}