日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

BZOJ3262: 陌上花开(cdq分治)

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

Description

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

Input

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

Output

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

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分治統計$(l,r)$這段區間的時候只需要考慮$b$和$c$的貢獻,而且只需要考慮區間$(l, mid)$對$mid + 1, r$的貢獻

用樹狀數組維護第三維的貢獻

?

#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; }

?

轉載于:https://www.cnblogs.com/zwfymqz/p/9282370.html

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。