隐藏页面特效

3262: 陌上花开

3262: 陌上花开

Time Limit: 20 Sec  Memory Limit: 256 MB
Submit: 2133  Solved: 954
[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

 

1 <= N <= 100,000, 1 <= K <= 200,000

 

Source

 
#include<cstdio> #include<algorithm> #define lowbit(x) (x&(-x)) using namespace std; inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } const int N=2e5+5; struct node{int opt,x,y,z,cnt,id;}q[N],tq[N]; int n,m,tot,sz,c[N],ans[N],Ans[N]; bool operator ==(const node &a,const node &b){ return a.x==b.x&&a.y==b.y&&a.z==b.z; } inline bool cmp1(const node &a,const node &b){ return a.x!=b.x?a.x<b.x: a.y!=b.y?a.y<b.y: a.z<b.z; } inline bool cmp2(const node &a,const node &b){ return a.y!=b.y?a.y<b.y: a.id<b.id; } void update(int p,int v){ for(int i=p;i<=n;i+=lowbit(i)) c[i]+=v; } int query(int p){ int res=0; for(int i=p;i;i-=lowbit(i)) res+=c[i]; return res; } void CDQ(int l,int r){ if(l==r) return ; int mid=l+r>>1,ql=l,qr=mid+1; for(int i=l;i<=mid;i++) q[i].opt=1; for(int i=mid+1;i<=r;i++) q[i].opt=2; for(int i=l;i<=r;i++) tq[i]=q[i]; sort(tq+l,tq+r+1,cmp2); for(int i=l;i<=r;i++){ if(tq[i].opt==1) update(tq[i].z,tq[i].cnt); if(tq[i].opt==2) ans[tq[i].id]+=query(tq[i].z); } for(int i=l;i<=r;i++){ if(tq[i].opt==1) update(tq[i].z,-tq[i].cnt); } CDQ(l,mid); CDQ(mid+1,r); } int main(){ m=read();n=read(); for(int i=1;i<=m;i++){ tq[i].x=read(); tq[i].y=read(); tq[i].z=read(); tq[i].cnt=1; } sort(tq+1,tq+m+1,cmp1); for(int i=1;i<=m;i++){ if(tq[i]==tq[i-1]) q[tot].cnt++; else q[++tot]=tq[i],q[tot].id=++sz; } sort(q+1,q+tot+1,cmp1); CDQ(1,tot); for(int i=1;i<=tot;i++) Ans[ans[q[i].id]+q[i].cnt-1]+=q[i].cnt; for(int i=0;i<m;i++) printf("%d\n",Ans[i]); return 0; }

 


__EOF__

本文作者shenben
本文链接https://www.cnblogs.com/shenben/p/6772545.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   神犇(shenben)  阅读(233)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
点击右上角即可分享
微信分享提示