bzoj 3265
水水模板题
#include <bits/stdc++.h> const int N = 2e5 + 10; struct Node { int x, y, z, ans, id; bool operator == (Node a) { return x == a.x && y == a.y && z == a.z; } } Ask[N]; int n, k; inline void In_put() { std:: cin >> n >> k; for(int i = 1; i <= n; i ++) std:: cin >> Ask[i].x >> Ask[i].y >> Ask[i].z; } struct Node_1 { int Tree[N]; inline int Lowbit(int x) {return x & (-x);} inline void Add(int x, int a) { if(!x) return ; while(x <= k) Tree[x] += a, x += Lowbit(x); } inline int Ass(int x) { int ret = 0; while(x) ret += Tree[x], x -= Lowbit(x); return ret; } } Bit; inline bool Cmpx(Node a, Node b) { return a.x < b. x || (a.x == b.x && a.y < b.y) || (a.x == b.x && a.y == b.y && a.z < b.z); } inline bool Cmpy(Node a, Node b) {return a.y < b.y; } Node a[N], b[N]; int Change[N]; void Cdq(int l, int r) { if(l >= r) return ; int mid = (l + r) >> 1; Cdq(l, mid); int js_a = 0; for(int i = l; i <= mid; i ++) a[++ js_a] = Ask[i]; std:: sort(a + 1, a + js_a + 1, Cmpy); int js_b = 0; for(int i = mid + 1; i <= r; i ++) b[++ js_b] = Ask[i]; std:: sort(b + 1, b + js_b + 1, Cmpy); int to_a = 1, to_b = 1, tot = 0; while(to_b <= js_b) { while(to_a <= js_a && a[to_a].y <= b[to_b].y) { Bit.Add(a[to_a].z, 1); Change[++ tot] = a[to_a].z; ++ to_a; } Ask[b[to_b].id].ans += Bit.Ass(b[to_b].z); ++ to_b; } for(int i = 1; i <= tot; i ++) Bit.Add(Change[i], -1); Cdq(mid + 1, r); } void Work() { std:: sort(Ask + 1, Ask + n + 1, Cmpx); for(int i = 1; i <= n; i ++) Ask[i].id = i; Cdq(1, n); } int Cnt[N]; void Get_Answer() { for(int i = n - 1; i >= 1; i --) if(Ask[i] == Ask[i + 1]) Ask[i].ans = std:: max(Ask[i].ans, Ask[i + 1].ans); for(int i = 1; i <= n; i ++) ++ Cnt[Ask[i].ans]; for(int i = 0; i < n; i ++) std:: cout << Cnt[i] << "\n"; } int main() { In_put(); Work(); Get_Answer(); return 0; }