1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| #include <bits/stdc++.h> using namespace std; using LL = long long; #define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i) #define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i) #ifdef zerol #define dbg(args...) do { cout << "\033[32;1m" << #args << " -> "; err(args); } while (0) #else #define dbg(...) #endif void err() { cout << "\033[39;0m" << endl; } template<template<typename...> class T, typename t, typename... Args> void err(T<t> a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); } template<typename T, typename... Args> void err(T a, Args... args) { cout << a << ' '; err(args...); } // ----------------------------------------------------------------------------- const int maxn = 1E5 + 100, maxk = 2E5 + 100; struct P { int x, y, z; int* ans; bool d1, d2; } a[maxn], b[maxn], c[maxn];
void go2(int l, int r) { // [l, r) if (l + 1 == r) return; int m = (l + r) / 2; go2(l, m); go2(m, r); FOR (i, l, m) b[i].d2 = 0; FOR (i, m, r) b[i].d2 = 1; merge(b + l, b + m, b + m, b + r, c + l, [](const P& a, const P& b)->bool { return a.z < b.z; }); int s = 0; FOR (i, l, r) { if (c[i].d1 && c[i].d2) *c[i].ans += s; s += !c[i].d1 && !c[i].d2; } FOR (i, l, r) b[i] = c[i]; }
void go1(int l, int r) { // [l, r) if (l + 1 == r) return; int m = (l + r) / 2; go1(l, m); go1(m, r); FOR (i, l, m) a[i].d1 = 0; FOR (i, m, r) a[i].d1 = 1; merge(a + l, a + m, a + m, a + r, b + l, [](const P& a, const P& b)->bool { return a.y < b.y; }); FOR (i, l, r) a[i] = b[i]; go2(l, r); }
int ans[maxn], cnt[maxn]; int n, k; int main() { cin >> n >> k; FOR (i, 0, n) scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z); sort(a, a + n, [](const P& a, const P& b)->bool { if (a.x != b.x) return a.x < b.x; if (a.y != b.y) return a.y < b.y; return a.z < b.z; }); FOR (i, 0, n) a[i].ans = &ans[i]; FORD (i, n - 2, -1) if (a[i].x == a[i + 1].x && a[i].y == a[i + 1].y && a[i].z == a[i + 1].z) ans[i] = ans[i + 1] + 1; go1(0, n); FOR (i, 0, n) cnt[ans[i]]++; FOR (i, 0, n) printf("%d\n", cnt[i]); }
|