# BZOJ 3262 陌上花开 cdq分治

#include <cstdio>
#include <algorithm>
using namespace std;
#define SZ 200005
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
int n, k, T[200005+1], G[100005];
struct node{int x, y, z, cnt, ans;} a[100005];
bool cmpy(node u, node v) {return u.y < v.y;}
bool cmpx(node u, node v) {
if (u.x != v.x) return u.x < v.x;
else if (u.y != v.y) return u.y < v.y;
else return u.z < v.z;
}
void add(int i, int x) {for(;i<=SZ;i+=i&-i)T[i]+=x;}
int sum(int i) {int s=0;for(;i>0;i-=i&-i)s+=T[i];return s;}

void cdq(int l, int r) {
if (l == r) {a[l].ans += a[l].cnt; return;}
int m = (l + r) / 2;
cdq(l, m), cdq(m + 1, r);
sort(a + l, a + m + 1, cmpy);
sort(a + m + 1, a + r + 1, cmpy);
int j = l;
FOR(i, m + 1, r) {
for (; j <= m && a[j].y <= a[i].y; ++j)
a[i].ans += sum(a[i].z);
}
FOR(i, l, j - 1) add(a[i].z, -a[i].cnt);
}

int main () {
// freopen("data.in", "r", stdin);
scanf("%d%d", &n, &k);
FOR(i, 0, n - 1)
scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z);
sort(a, a + n, cmpx);
int tot = 0;
FOR(i, 0, n - 1) {
if (i && a[i].x == a[i - 1].x && a[i].y == a[i - 1].y
&& a[i].z == a[i - 1].z)
a[tot - 1].cnt++;
else
a[tot] = a[i], a[tot++].cnt = 1;
}
cdq(0, tot - 1);
FOR(i, 0, tot - 1) G[a[i].ans] += a[i].cnt;
FOR(i, 1, n) printf("%d\n", G[i]);
return 0;
}

posted @ 2018-10-25 00:38  gaawing  阅读(158)  评论(0编辑  收藏  举报