3262: 陌上花开
Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 2493 Solved: 1113
[ Submit][ Status][ Discuss]
Description
Input
Output
Sample Input
3 3 3
2 3 3
2 3 1
3 1 1
3 1 2
1 3 1
1 1 2
1 2 2
1 3 2
1 2 1
Sample Output
1
3
0
1
0
1
0
0
1
HINT
1 <= N <= 100,000, 1 <= K <= 200,000
Source
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<time.h>
#include<math.h>
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<functional>
using namespace std;
#define ll __int64
#define inf 1000000000
#define mod 1000000007
#define maxn 800100
#define lowbit(x) (x&-x)
#define eps 1e-9
struct node
{
int x,y,z,sum,ans;
bool operator < (const node &b) const
{
if(x<b.x || x==b.x && y<b.y || x==b.x && y==b.y && z<b.z)
return 1;
return 0;
}
}a[maxn],q[maxn];
int ans[maxn],n,k,c[maxn];
void update(int x,int val)
{
while(x<=k)
{
c[x]+=val;
x+=lowbit(x);
}
}
int query(int x)
{
int res=0;
while(x)
{
res+=c[x];
x-=lowbit(x);
}
return res;
}
bool comp(node a,node b)
{
if(a.z<b.z || a.z==b.z && a.y<b.y || a.z==b.z && a.y==b.y && a.x<b.x)
return 1;
return 0;
}
void cdq(int l,int r)
{
if(l==r)
return;
int i,ls,rs,m=(l+r)/2;
for(i=l;i<=r;i++)
{
if(a[i].z<=m)
update(a[i].y,a[i].sum);
else
a[i].ans+=query(a[i].y);
}
for(i=l;i<=r;i++)
if(a[i].z<=m)
update(a[i].y,-a[i].sum);
ls=l;rs=m+1;
for(i=l;i<=r;i++)
{
if(a[i].z<=m)
q[ls++]=a[i];
else
q[rs++]=a[i];
}
for(i=l;i<=r;i++)
a[i]=q[i];
cdq(l,m);cdq(m+1,r);
}
int main(void)
{
int i,cnt=0;
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++)
{
scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
a[i].sum=1;
}
sort(a+1,a+n+1);
for(i=1;i<=n;i++)
{
if(a[i].x==a[i-1].x && a[i].y==a[i-1].y && a[i].z==a[i-1].z)
{
a[cnt].sum++;
continue;
}
a[++cnt]=a[i];
}
sort(a+1,a+cnt+1,comp);
for(i=1;i<=cnt;i++)//将第三维离散化,变成1到cnt的全排列
a[i].z=i;
sort(a+1,a+cnt+1);
cdq(1,cnt);
for(i=1;i<=cnt;i++)
{
a[i].ans+=a[i].sum-1;//要把相等属性的加上
ans[a[i].ans]+=a[i].sum;
}
for(i=0;i<=n-1;i++)
printf("%d\n",ans[i]);
return 0;
}