本质上就是暴力
用分块优化而已
时间复杂度(O(knsqrt n))
在高维时候可以把K-D Tree吊起来打
cdq分治连影子都没了
/*
@Date : 2019-08-13 19:48:10
@Author : Adscn (adscn@qq.com)
@Link : https://www.cnblogs.com/LLCSBlog
*/
#include<bits/stdc++.h>
using namespace std;
#define IL inline
#define RG register
#define gi getint()
#define gc getchar()
#define File(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
IL int getint()
{
RG int xi=0;
RG char ch=gc;
bool f=0;
while(ch<'0'||ch>'9')ch=='-'?f=1:f,ch=gc;
while(ch>='0'&&ch<='9')xi=(xi<<1)+(xi<<3)+ch-48,ch=gc;
return f?-xi:xi;
}
template<typename T>
IL void pi(T k,char ch=0)
{
if(k<0)k=-k,putchar('-');
if(k>=10)pi(k/10,0);
putchar(k%10+'0');
if(ch)putchar(ch);
}
const int N=1e5+7,SQRN=sqrt(N)+7;
typedef bitset<N> Bit;
Bit bit[3][SQRN];
int val[3][N];
int tmp[N];
int siz[3];
vector<int>lst[3][N];
int bks,bk[N];
Bit getset(int p,int v){
int st=bk[v=val[p][v]]-1;
static Bit ans;ans.reset();
if(st<0)return ans;
ans=bit[p][st];
for(RG int i=max(st*bks+1-bks,0);i<=v;++i)for(auto && j:lst[p][i])ans.set(j);
return ans;
}
int ans[N];
int main(void)
{
int n=gi,k=gi;k=3;
for(RG int i=1;i<=n;++i)
for(RG int j=0;j<k;++j)
val[j][i]=gi;
int msiz=0;
for(RG int i=0;i<k;++i)
{
memcpy(tmp+1,&val[i][1],sizeof(int) * n);
sort(tmp+1,tmp+n+1);
msiz=max(msiz,siz[i]=unique(tmp+1,tmp+n+1)-tmp-1);
for(RG int j=1;j<=n;++j)lst[i][val[i][j]=lower_bound(tmp+1,tmp+siz[i]+1,val[i][j])-tmp].push_back(j);
}
bks=sqrt(msiz);
static Bit w;
for(RG int i=1;i<=n;++i)bk[i]=(i-1)/bks+1;
for(RG int j=0;j<k;++j){
w.reset();
for(RG int i=1;i<=siz[j];++i)
{
for(auto && t:lst[j][i])w.set(t);
if(bk[i]!=bk[i+1])bit[j][bk[i]]=w;
}
}
for(RG int i=1;i<=n;++i)
{
w.set();
for(RG int j=0;j<k;++j)w&=getset(j,i);
++ans[w.count()];
}
for(RG int i=1;i<=n;++i)pi(ans[i],'
');
return 0;
}