标签:turn void ret end ++ owb int clu lan
#include<bits/stdc++.h>
using namespace std;
const int maxn=200005;
struct node{
int a;
int b;
int c;
int cnt;
int ans;
}s1[maxn],s2[maxn];
int n,m,k,mx,top,su[maxn];
int c[maxn];
bool cmp1(node x,node y)
{
if(x.a==y.a)
{
if(x.b==y.b)
return x.c<y.c;
else return x.b<y.b;
}
else return x.a<y.a;
}
bool cmp2(node x,node y)
{
if(x.b==y.b)
return x.c<y.c;
else return x.b<y.b;
}
int lowbit(int x)
{
return x&(-x);
}
void add(int x,int y)
{
while(x<=mx)
{
c[x]=c[x]+y;
x+=lowbit(x);
}
}
int query(int x)
{
int sum=0;
while(x)
{
sum+=c[x];
x-=lowbit(x);
}
return sum;
}
void cdq(int l,int r)
{
if(l==r)
return ;
int mid=(l+r)>>1;
cdq(l,mid);
cdq(mid+1,r);
sort(s2+l,s2+mid+1,cmp2);
sort(s2+1+mid,s2+r+1,cmp2);
int i,j=l;
for(int i=mid+1;i<=r;i++)
{
while(s2[i].b>=s2[j].b&&j<=mid)
{
add(s2[j].c,s2[j].cnt);
j++;
}
s2[i].ans+=query(s2[i].c);
}
for(i=l;i<j;++i)
add(s2[i].c,-s2[i].cnt);
}
int main()
{
cin>>n>>k;
mx=k;
for(int i=1;i<=n;i++)
{
int a,b,c;
cin>>a>>b>>c;
s1[i].a=a;
s1[i].b=b;
s1[i].c=c;
}
sort(s1+1,s1+1+n,cmp1);
for(int i=1;i<=n;i++)
{
top++;
if(s1[i].a!=s1[i+1].a||s1[i].b!=s1[i+1].b||s1[i].c!=s1[i+1].c)
{
m++;
s2[m].a=s1[i].a;
s2[m].b=s1[i].b;
s2[m].c=s1[i].c;
s2[m].cnt=top;
top=0;
}
}
cdq(1,m);
for(int i=1;i<=m;i++)
su[s2[i].ans+s2[i].cnt-1]+=s2[i].cnt;
for(int i=0;i<n;i++)
cout<<su[i]<<endl;
return 0;
}
标签:turn void ret end ++ owb int clu lan
原文地址:https://www.cnblogs.com/bangdexuanyuan/p/13424513.html