https://www.luogu.org/problemnew/show/P3810
复习板子,重要的题就真的要写三遍???之前写过一篇博客了,不过之前写的那个板子的sort用的规则真是沙雕
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
int n,k,tot=0;
struct flos{
int x,y,z;
int ans,cnt;
}f[maxn];
int num[maxn]={},t[maxn*2]={};
inline bool mcmp1(flos a,flos b){
if(a.x==b.x){
if(a.y==b.y)return a.z<b.z;
return a.y<b.y;
}
return a.x<b.x;
}
inline bool mcmp2(flos a,flos b){
if(a.y==b.y){
if(a.z==b.z)return a.x<b.x;
return a.z<b.z;
}
return a.y<b.y;
}
void addt(int x,int v){
while(x<=k){
t[x]+=v;
x+=(x&-x);
}
}
int gett(int x){
int tsn=0;
while(x){
tsn+=t[x];
x-=(x&-x);
}return tsn;
}
void mcdq(int l,int r){
if(l==r){ f[l].ans+=f[l].cnt-1; return; }
int mid=(l+r)/2;
mcdq(l,mid); mcdq(mid+1,r);
sort(f+l,f+mid+1,mcmp2);
sort(f+mid+1,f+r+1,mcmp2);
int j=l;
for(int i=mid+1;i<=r;++i){
while(f[j].y<=f[i].y&&j<=mid){addt(f[j].z,f[j].cnt);++j;}
f[i].ans+=gett(f[i].z);
}
for(int i=l;i<j;++i)addt(f[i].z,-f[i].cnt);
}
int main(){
scanf("%d%d",&n,&k);
for(int i=1; i<=n; ++i)scanf("%d%d%d",&f[i].x,&f[i].y,&f[i].z);
sort(f+1,f+1+n,mcmp1);
//for(int i=1;i<=n;++i)cout<<f[i].x<<f[i].y<<f[i].z<<endl;
for(int i=1; i<=n; ++i){
if(i!=1 && f[i].x==f[i-1].x && f[i].y==f[i-1].y && f[i].z==f[i-1].z)++f[tot].cnt;
else{ f[++tot]=f[i]; f[tot].cnt=1;}
}
mcdq(1,tot);
for(int i=1;i<=tot;++i)num[f[i].ans]+=f[i].cnt;
for(int i=0;i<n;++i)printf("%d\n",num[i]);
return 0;
}