Color the ball
来源:互联网 发布:图片上传到淘宝变模糊 编辑:程序博客网 时间:2024/06/05 19:22
Color the ball - HDU 1556 - 线段树 区间更新单点查询
国际惯例中文题目不解释,思路直接裸线段树,Lazy思想入门题。
Lazy传送门:延迟更新详解
AC代码:
//// main.cpp// L//// Created by LucienShui on 2017/5/28.// Copyright © 2017年 LucienShui. All rights reserved.//#include <iostream>#include <algorithm>#include <set>#include <string>#include <vector>#include <queue>#include <map>#include <iomanip>#include <cstdio>#include <cstring>#include <cmath>#include <cctype>#define memset(a,b) memset(a,b,sizeof(a))#define il inline#define ll long long#define ull unsigned long longusing namespace std;#define ls (u<<1)#define rs (u<<1|1)#define lson u<<1,l,mid#define rson u<<1|1,mid+1,rconst int maxn = 100000+7;int node[maxn<<2];void pushdown(int u) { node[ls] += node[u]; node[rs] += node[u]; node[u]=0;}void update(int u, int l, int r, int b, int e) { if(b <= l && r <= e) { node[u]++; return ; } if(node[u]!=0) pushdown(u); int mid = (l+r)>>1; if(e<=mid) update(lson,b,e); else if(b>mid) update(rson,b,e); else { update(lson,b,e); update(rson,b,e); }}int query(int u, int l, int r, int x) { if(l==r&&l==x) { return node[u]; } if(node[u]!=0) pushdown(u); int mid = (l+r)>>1; if(x<=mid) return query(lson,x); else return query(rson,x);}int main (){#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin);#endif // ONLINE_JUDGE int n; while(scanf("%d",&n),n) { memset(node,0); for(int i=0,a,b ; 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;}
阅读全文
1 0
- hdu1556 color the ball
- HDOJ Color the ball
- Color the ball
- Color the Ball
- hdu1556 Color the ball
- hdu1556 Color the ball
- hdu_1556 Color the ball
- hdu1556 Color the ball
- Color the ball----HDOJ1556
- HDU1556 Color the ball
- Color the ball
- Color the ball
- hdu1556 Color the ball
- hdu1556--Color the ball
- HDU_1556 Color the ball
- Color the ball HDU1556
- HDU1556 Color the ball
- Color the ball
- 思维的局限
- 数据结构之通用树
- (144)距离场环境遮挡
- For parallel
- C++ 全局变量、局部变量、静态全局变量、静态局部变量的区别
- Color the ball
- LeetCode (Unique Binary Search Trees)
- 编译原理:素短语、短语、直接短语、句柄的基本概念
- Jenkins初识
- A. Vladik and Courtesy
- 搬运工整理之 HoloLens 开发环境搭建 01
- Javascript实现二叉搜索树
- 输入输出练习
- Date对象