版本比较
板子
正文
增加 77 行删除 0 行
387 行未改动全部展开388389390391387 行未改动全部展开cout << (ans == inf? -1: ans);return 0;}```387 行未改动全部展开388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468387 行未改动全部展开cout << (ans == inf? -1: ans);return 0;}``````cpp#include<bits/stdc++.h>#define mid (L + R >> 1)#define int long longusing namespace std;const int N = 2e5 + 5;struct node{int a,b,c,id,w;}c[N];int n,ans[N],t[N],k;bool cmp1 (node a, node b) {if (a.a == b.a) { // a b cif (a.b == b.b)return a.c < b.c;return a.b < b.b;}return a.a < b.a;}bool cmp2 (node a, node b) { // b cif (a.b == b.b)return a.c < b.c;return a.b < b.b;}namespace Bit {int t[N];int res (int x) {int ans = 0;for(;x > 0; x -= x & -x)ans += t[x];return ans;}void add (int x, int w) {for (; x <= k; x += x & -x)t[x] += w;}}void CDQ (int L, int R){if (L == R) return ;int p = L;CDQ(L, mid), CDQ(mid+1,R);sort(c + L, c + mid + 1, cmp2);sort(c + mid + 1, c + R + 1, cmp2) ;for (int i = mid + 1; i <= R; i++) {while (p <= mid && c[p].b <= c[i].b)Bit::add(c[p].c, c[p].w), p++;ans[c[i].id] += Bit::res(c[i].c);}for (int i = L; i < p; i++)Bit::add(c[i].c, -c[i].w);}signed main () {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cin >> n >> k;for (int i = 1; i <= n; i++) {cin >> c[i].a >> c[i].b >> c[i].c;c[i].id = i;}sort(c + 1, c + 1 + n, cmp1);int tot = 0;for (int i = 1; i <= n; i++) {if (c[i].a != c[i-1].a || c[i].c != c[i-1].c || c[i].b != c[i-1].b)c[++tot] = c[i];c[tot].w++;}CDQ(1, tot);for (int i = 1; i <= tot; i++)t[ans[c[i].id] + c[i].w - 1] += c[i].w;for (int i = 0; i < n; i++)cout << t[i] << '\n';return 0;}## CDQ```