#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define maxn 100005
#define maxm 200005
#define maxk 2000005
using namespace std; int n,K,temp,tot,root[maxm*],ans[maxn],Ans[maxn],sum[maxn],fa[maxk],size[maxk],times[maxk],son[maxk][],val[maxk];
struct seg{
int x,y,z;
}a[maxn],b[maxn];
bool comp(seg x,seg 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;
}
struct Tsegment{
void prepare(){tot=,memset(times,,sizeof(times)),memset(son,,sizeof(son));}
void query(int k,int x,int op){
int y=root[k]; if (y==) return; bool bo;
for (;;){
if (y==) break;
bo=;
if (val[y]==x) ans[op]+=(size[son[y][]]+times[y]),bo=;
else if (x>val[y]) ans[op]+=(size[son[y][]]+times[y]),y=son[y][];
else y=son[y][];
if (bo==) break;
}
}
int which(int x){
return son[fa[x]][]==x;
}
void update(int x){
size[x]=size[son[x][]]+size[son[x][]]+times[x];
}
void rotata(int x){
int y=fa[x],d=which(x),dd=which(y);
if (fa[y]) son[fa[y]][dd]=x; fa[x]=fa[y];
fa[son[x][d^]]=y,son[y][d]=son[x][d^];
fa[y]=x,son[x][d^]=y,update(y);
}
void splay(int x,int goal,int op){
while (fa[x]!=goal){
if (fa[fa[x]]==goal) rotata(x);
else if (which(x)==which(fa[x])) rotata(fa[x]),rotata(x);
else rotata(x),rotata(x);
}
update(x); if (goal==) root[op]=x;
}
void insert(int k,int x,int z){
int y=root[k]; bool bo;
if (y==){
root[k]=++tot,val[tot]=x,size[tot]=times[tot]=z,fa[tot]=son[tot][]=son[tot][]=;
return;
}
for (;;){
bo=;
if (val[y]==x) times[y]+=z,size[y]+=z,bo=,splay(y,,k);
else if (x<val[y]){
if (!son[y][]) val[++tot]=x,son[y][]=tot,fa[tot]=y,size[tot]=times[tot]=z,bo=,splay(tot,,k);
else y=son[y][];
}else{
if (!son[y][]) val[++tot]=x,son[y][]=tot,fa[tot]=y,size[tot]=times[tot]=z,bo=,splay(tot,,k);
else y=son[y][];
}
if (bo==) break;
}
}
}Splay;
struct Fsegment{
void prepare(){memset(root,,sizeof(root));}
void query(int k,int l,int r,int x,int y,int z,int op){
if (l>=x&&r<=y){
Splay.query(k,z,op);
return;
}int mid=(l+r)/;
if (x<=mid) query(k*,l,mid,x,y,z,op);
if (y>mid) query(k*+,mid+,r,x,y,z,op);
}
void insert(int k,int l,int r,int x,int y,int z){
Splay.insert(k,y,z);
if (l==r) return; int mid=(l+r)/;
if (x<=mid) insert(k*,l,mid,x,y,z);
else insert(k*+,mid+,r,x,y,z);
}
}Tree;
struct Ksegment{
void work(){
memset(ans,,sizeof(ans));
for (int i=;i<=temp;i++){
Tree.query(,,K,,b[i].y,b[i].z,i);
Tree.insert(,,K,b[i].y,b[i].z,sum[i]);
}
memset(Ans,,sizeof(Ans));
for (int i=;i<=temp;i++) Ans[ans[i]+sum[i]-]+=sum[i];
for (int i=;i<n;i++) printf("%d\n",Ans[i]);
}
}Task;
int main(){
memset(fa,,sizeof(fa));
memset(son,,sizeof(son));
memset(val,,sizeof(val));
a[].x=a[].y=a[].z=;
scanf("%d%d",&n,&K);
for (int i=;i<=n;i++) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
sort(a+,a+n+,comp);
memset(sum,,sizeof(sum));
temp=tot=;
for (int i=;i<=n;i++){
if (a[i].x==a[i-].x&&a[i].y==a[i-].y&&a[i].z==a[i-].z) sum[temp]++;
else sum[++temp]=,b[temp].x=a[i].x,b[temp].y=a[i].y,b[temp].z=a[i].z;
}
Tree.prepare();
Task.work();
return ;
}
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3262
题目大意:见题目。
做法:上次我用的是cdq分治+树状数组,这次写的是线段树套splay,比较裸的树套树了,,,一维排序,另外两维在树套树上维护一下即可。
树套树。