# bzoj3262 陌上花开

## 3262: 陌上花开

Time Limit: 20 Sec  Memory Limit: 256 MB
Submit: 2808  Solved: 1258
[Submit][Status][Discuss]

10 3
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

3
1
3
0
1
0
1
0
0
1

## HINT

1 <= N <= 100,000, 1 <= K <= 200,000

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int n,k,tot,ans[100010],cnt,c[200010];

struct node
{
int a,b,c,d,f;
}e[100010],p[100010];

bool cmp(node a,node b)
{
if (a.a == b.a && a.b == b.b)
return a.c < b.c;
if (a.a == b.a)
return a.b < b.b;
return a.a < b.a;
}

{
while (x <= k)
{
c[x] += v;
x += x & (-x);
}
}

int query(int x)
{
int res = 0;
while (x)
{
res += c[x];
x -= x & (-x);
}
return res;
}

void solve(int l,int r)
{
if (l >= r)
return;
int mid = (l + r) >> 1;
solve(l,mid);
solve(mid + 1,r);
cnt = l;
int i = l,j = mid + 1;
while (i <= mid || j <= r)
{
if (j > r || (i <= mid && e[i].b <= e[j].b))
{
p[cnt++] = e[i++];
}
else
{
e[j].f += query(e[j].c);
p[cnt++] = e[j++];
}
}
for (int i = l; i <= mid; i++)
for (int i = l; i <= r; i++)
e[i] = p[i];
}

int main()
{
scanf("%d%d",&n,&k);
for (int i = 1; i <= n; i++)
{
scanf("%d%d%d",&e[i].a,&e[i].b,&e[i].c);
e[i].d = 1;
}
tot = 1;
sort(e + 1,e + 1 + n,cmp);
for (int i = 2; i <= n; i++)
{
if (e[i].a == e[tot].a && e[i].b == e[tot].b && e[i].c == e[tot].c)
e[tot].d++;
else
e[++tot] = e[i];
}
solve(1,tot);
for (int i = 1; i <= tot; i++)
ans[e[i].d + e[i].f - 1] += e[i].d;
for (int i = 0; i < n; i++)
printf("%d\n",ans[i]);

return 0;
}

posted @ 2018-01-05 19:16  zbtrs  阅读(135)  评论(0编辑  收藏  举报