日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

BZOJ3262: 陌上花开(cdq分治)

發(fā)布時間:2024/4/17 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 BZOJ3262: 陌上花开(cdq分治) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Time Limit:?20 Sec??Memory Limit:?256 MB
Submit:?3627??Solved:?1705
[Submit][Status][Discuss]

Description

有n朵花,每朵花有三個屬性:花形(s)、顏色(c)、氣味(m),用三個整數(shù)表示。 現(xiàn)在要對每朵花評級,一朵花的級別是它擁有的美麗能超過的花的數(shù)量。 定義一朵花A比另一朵花B要美麗,當(dāng)且僅Sa>=Sb,Ca>=Cb,Ma>=Mb。 顯然,兩朵花可能有同樣的屬性。需要統(tǒng)計出評出每個等級的花的數(shù)量。

Input

第一行為N,K (1 <= N <= 100,000, 1 <= K <= 200,000 ), 分別表示花的數(shù)量和最大屬性值。 以下N行,每行三個整數(shù)si, ci, mi (1 <= si, ci, mi <= K),表示第i朵花的屬性

Output

包含N行,分別表示評級為0...N-1的每級花的數(shù)量。

Sample Input

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

Sample Output

3
1
3
0
1
0
1
0
0
1

HINT

Source

感覺cdq分治和歸并排序很像qwq。

第一維可以用排序搞掉

這樣我們用cdq分治統(tǒng)計$(l,r)$這段區(qū)間的時候只需要考慮$b$和$c$的貢獻,而且只需要考慮區(qū)間$(l, mid)$對$mid + 1, r$的貢獻

用樹狀數(shù)組維護第三維的貢獻

?

#include<cstdio> #include<algorithm> #define lowbit(x) ((x) & (-x)) using namespace std; const int MAXN = 200001; inline int read() {char c = getchar(); int x = 0, f = 1;while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();return x * f; } int N, Max; struct Node {int a, b, c, f, w;bool operator < (const Node &rhs) const{return (a == rhs.a && b == rhs.b) ? (c < rhs.c) : (a == rhs.a ? b < rhs.b : a < rhs.a);} }A[MAXN], tp[MAXN]; int num = 0, ans[MAXN]; int T[MAXN]; void Add(int pos, int val) {for(int i = pos; i <= Max; i += lowbit(i)) T[i] += val; } int Query(int pos) {int ans = 0;for(int i = pos; i; i -= lowbit(i)) ans += T[i];return ans; } void CDQ(int l, int r) {if(l == r) return;int mid = l + r >> 1;CDQ(l, mid); CDQ(mid + 1, r);int i = l, j = mid + 1, P = l;while(i <= mid || j <= r) {if(j > r || (i <= mid && A[i].b <= A[j].b)) Add(A[i].c, A[i].w), tp[P++] = A[i++];else A[j].f += Query(A[j].c), tp[P++] = A[j++];}for(int i = l; i <= mid; i++) Add(A[i].c, -A[i].w);for(int i = l; i <= r; i++) A[i] = tp[i]; } int main() { #ifdef WIN32freopen("a.in", "r", stdin); #endifN = read(); Max = read();for(int i = 1; i <= N; i++) A[i].a = read(), A[i].b = read(), A[i].c = read(), A[i].w = 1;sort(A + 1, A + N + 1);num = 1;for(int i = 2; i <= N; i++)if(A[i].a == A[num].a && A[i].b == A[num].b && A[i].c == A[num].c) A[num].w++;else A[++num] = A[i];CDQ(1, num);for(int i = 1; i <= num; i++) ans[A[i].f + A[i].w - 1] += A[i].w;for(int i = 0; i <= N - 1; i++)printf("%d\n", ans[i]);return 0; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/zwfymqz/p/9282370.html

總結(jié)

以上是生活随笔為你收集整理的BZOJ3262: 陌上花开(cdq分治)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。