hdu1556 线段树 区间修改
来源:互联网 发布:手机上传图片asp源码 编辑:程序博客网 时间:2024/05/16 07:14
#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>#include <cmath>using namespace std;#define maxn 1100000#define lson rt<<1,l,m#define rson rt<<1|1,m+1,rint tree[maxn<<2];void pushdown(int rt){ if(tree[rt]) { tree[rt<<1]+=tree[rt]; tree[rt<<1|1]+=tree[rt]; tree[rt]=0; }}void update(int rt,int l,int r,int x,int y){ if(x<=l&&y>=r) { tree[rt]+=1; return ; } pushdown(rt); int m=(l+r)>>1; if(x<=m) { update(lson,x,y); } if(y>m) { update(rson,x,y); }}int query(int rt,int l,int r,int x){ if(l==r) { return tree[rt]; } pushdown(rt); int m=(l+r)>>1; if(x<=m) return query(lson,x); else return query(rson,x);}int main(){ int n,m; int a,b,c; while(scanf("%d",&n)&&n) { memset(tree,0,sizeof(tree)); for(int i=1;i<=n;i++) { scanf("%d%d",&a,&b); update(1,1,n,a,b); } for(int i=1;i<n;i++) { printf("%d ",query(1,1,n,i)); } printf("%d\n",query(1,1,n,n)); } return 0;}
0 0
- hdu1556 线段树 区间修改
- hdu1556(树状数组/线段树,区间修改,点查询)
- hdu1556 Color the ball(线段树区间修改)
- hdu1556 线段树更新区间
- hdu1556 线段树区间更新 求单点
- hdu1556 Color the ball【树状数组 || 线段树 || 技巧*区间修改】
- HDU1556:Color the ball(线段树区间更新)
- hdu1556 Color the ball(线段树区间更新)
- hdu1556 Color the ball(线段树区间更新)
- HDU1556 Color the ball(线段树区间更新)
- hdu1556 Color the ball 线段树区间染色问题
- HDU1556:Color the ball(线段树区间更新)
- HDU1556 线段树入门
- 经典 hdu1556 线段树
- HDU1556 线段树
- HDU1556(线段树)
- HDU1556 - 线段树基础
- hdu1556(线段树)
- "黑马程序员"面向对象的初步了解
- 发布一个简单的Web Service接口
- 搬寝室 -HDU 1421 dp
- HDU 3001 Travelling (三进制状态压缩 DP)
- Struts2笔记二之struts.xml
- hdu1556 线段树 区间修改
- 一笑而过
- LeetCode-Spiral Matrix
- CentOS 6.5 64位 MySQL源码安装
- 呵呵
- poj 2352 && hdu 1541 Stars (树状数组水题)
- linux批处理命令
- POJ 3264 Balanced Lineup ST表
- 为数据挖掘,数据分析师做准备