HDU1556(线段树)
来源:互联网 发布:泰瑟电击枪淘宝地址 编辑:程序博客网 时间:2024/05/30 19:34
代码:
#include<stdio.h>#define maxn 1000005int nn;struct node{ int l,r,sum;}str[maxn];void build(int l,int r,int n){ str[n].l=l; str[n].r=r; str[n].sum=0; if(l==r) return; int temp=(l+r)/2; build(l,temp,2*n); build(temp+1,r,2*n+1);}void color(int a,int b,int n){ if(str[n].l==a&&str[n].r==b) { str[n].sum++; return; } int temp=(str[n].l+str[n].r)/2; if(b<=temp) color(a,b,2*n); else if(a>temp) color(a,b,2*n+1); else { color(a,temp,2*n); color(temp+1,b,2*n+1); }}void out(int n,int sum){ if(str[n].l==str[n].r) { printf("%d",sum+str[n].sum); if(str[n].l!=nn) printf(" "); return; } out(2*n,sum+str[n].sum); out(2*n+1,sum+str[n].sum);}int main(){ while(scanf("%d",&nn),nn!=0) { build(1,nn,1); for(int i=1;i<=nn;i++) { int a,b; scanf("%d%d",&a,&b); color(a,b,1); } out(1,0); printf("\n"); }}
0 0
- HDU1556(线段树)
- HDU1556 线段树入门
- 经典 hdu1556 线段树
- HDU1556 线段树
- HDU1556 - 线段树基础
- hdu1556(线段树)
- hdu1556 线段树 区间修改
- hdu1556 线段树更新区间
- hdu1556--刷气球--线段树
- hdu1556 线段树段更新(简单题)
- HDU1556 Color the ball(线段树区间更新)
- hdu1556(树状数组/线段树,区间修改,点查询)
- hdu1556 Color the ball(线段树区间修改)
- HDU1556 Color the ball(线段树)
- hdu1556-color the ball 线段树
- hdu1556 Color the ball 线段树
- hdu1556 线段树区间更新 求单点
- hdu1556 Color the ball 线段树
- php第一个解决的问题
- 二级列表展示网络数据
- ubuntu 主题
- CMD命令:开始->运行->键入cmd或command(在命令行里可以看到系统版本、文件系统版本)
- Android导入三方jar未发现
- HDU1556(线段树)
- Unity3d中MonoBehaviour函数调用顺序
- 大型WEB网站架构深入分析
- 阶乘之和
- JpaSqlDao
- JavaScript-可维护代码编写,函数式编程与纯函数
- 2016"百度之星" - 初赛(Astar Round2A)
- VS2012中GDAL环境变量的搭建
- BZOJ 4596: [Shoi2016]黑暗前的幻想乡