poj 2352
来源:互联网 发布:数据分析经理 编辑:程序博客网 时间:2024/05/16 13:55
线段树,顺序存储实现
#include <stdio.h>#include <string.h>const int maxx=32000;const int maxn=15000;int l[3*(maxx+1)],h[3*(maxx+1)],w[3*(maxx+1)];int N;int ans[maxn];void Create(int t,int s,int f){l[t]=s;h[t]=f;if(s<f){int mid=(s+f)/2;Create(2*t+1,s,mid);Create(2*t+2,mid+1,f);}}void Init(int t){w[t]=0;if(l[t]<h[t]){Init(2*t+1);Init(2*t+2);}}int GetAmount(int t,int f ){if(h[t]==f) return w[t];else{int mid=(l[t]+h[t])/2;if(mid>=f) return GetAmount(2*t+1,f);elsereturn w[2*t+1]+GetAmount(2*t+2,f);}}void Insert(int t,int x){if(l[t]<=x&&x<=h[t]){w[t]++;if(l[t]!=h[t]){int mid=(l[t]+h[t])/2;Insert(2*t+1,x);Insert(2*t+2,x);}}}int main(){Create(0,0,maxx);while(scanf("%d",&N)!=EOF){Init(0);memset(ans,0,sizeof(ans));int i,x,y,level;for(i=0;i<N;i++){scanf("%d%d",&x,&y);level=GetAmount(0,x);ans[level]++;Insert(0,x);}for(i=0;i<N;i++){printf("%d\n",ans[i]);}}return 0;}
- poj 2352
- poj 2352
- poj 2352
- poj 2352
- poj 2352
- poj 2352
- poj 2352
- poj 2352
- poj 2352
- poj-2352
- POJ 2352
- poj 2352
- poj-2352
- poj 2352
- poj 2352
- POJ 2352
- poj 2352
- POJ 2352 STARS
- Server Application Unavailable解决方法
- 友善的HLY101ML282-18A
- 如何将一棵树转换成二叉树
- [带权并查集] poj 1733 Parity game
- (转)程序员应该是一个创造性的职业
- poj 2352
- vi(vim)使用入门
- 《HTML5与CSS3权威指南》学习笔记1
- Gallery相片滑动实例
- 浅谈游戏辅助开发
- linux下查看进程内存使用情况
- 嵌入式系统设备驱动接口的C#编程
- 在C/python中执行linux命令并得到返回值以及输出
- 由个人经验分析百度零收录的原因