HDU1556:Color the ball(简单的线段树区域更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1556
当N = 0,输入结束。
模板题,没什么好说的,搜了一下这题看见大家都是用树状数组做的,有空学一下。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#define N 1000010
using namespace std;
struct node
{
int l,r,lz,w;
} q[*N];
int n;
void pushdown(int rt)
{
if(q[rt].lz)
{
q[rt<<].lz+=q[rt].lz;
q[rt<<|].lz+=q[rt].lz;
q[rt<<].w+=q[rt].lz;
q[rt<<|].w+=q[rt].lz;
q[rt].lz=;
}
}
void build(int l,int r,int rt)
{
q[rt].l=l;
q[rt].r=r;
q[rt].w=;
q[rt].lz=;
if(l==r)
return ;
int mid=(l+r)>>;
build(l,mid,rt<<);
build(mid+,r,rt<<|);
return ;
}
void update(int lf,int rf,int l,int r,int rt)
{
if(lf<=l&&rf>=r)
{
q[rt].w+=;
q[rt].lz+=;
return ;
}
pushdown(rt);
int mid=(l+r)>>;
if(lf<=mid) update(lf,rf,l,mid,rt<<);
if(rf>mid) update(lf,rf,mid+,r,rt<<|);
}
void query(int l,int r,int rt)
{
if(l==r)
{
if(l==)
printf("%d",q[rt].w);
else printf(" %d",q[rt].w);
return ;
}
pushdown(rt);
int mid=(l+r)>>;
query(l,mid,rt<<);
query(mid+,r,rt<<|);
return ;
}
int main()
{
int s1,s2;
while(scanf("%d",&n)!=EOF&&n!=)
{
build(,n,);
for(int i=; i<n; i++)
{
scanf("%d%d",&s1,&s2);
update(s1,s2,,n,);
}
query(,n,);
printf("\n");
}
}
HDU1556:Color the ball(简单的线段树区域更新)的更多相关文章
- hdu1556 Color the ball 简单线段树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 简单的线段树的应用 直接贴代码了: 代码: #include<iostream> # ...
- Color the ball HDU - 1556 (线段树)
思路:线段树,区间更新 #include<iostream> #include<vector> #include<string> #include<cmath ...
- HDU5023:A Corrupt Mayor's Performance Art(线段树区域更新+二进制)
http://acm.hdu.edu.cn/showproblem.php?pid=5023 Problem Description Corrupt governors always find way ...
- HDU1698:Just a Hook(线段树区域更新模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=1698 Problem Description In the game of DotA, Pudge’s meat ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU1556 Color the ball & 牛客 contest 135-I 区间 [差分标记]
一.差分标记介绍 差分标记用来解决针对区间(修改-查询)的问题,复杂度比线段树要更低.推荐这个博客. 例如,给数组中处于某个区间的数进行加减操作,然后查询某个位置上数的变化值. 二.HDU1556 C ...
- 【arc073e】Ball Coloring(线段树,贪心)
[arc073e]Ball Coloring(线段树,贪心) 题面 AtCoder 洛谷 题解 大型翻车现场,菊队完美压中男神的模拟题 首先钦定全局最小值为红色,剩下的袋子按照其中较大值排序. 枚举前 ...
- ZOJ 1610 Count the Color(线段树区间更新)
描述Painting some colored segments on a line, some previously painted segments may be covered by some ...
随机推荐
- DoBox 下载
DoBox下载 一款简单十分好用的办公助手,用于记录您接下来需要做的事情.待办事项小工具 - DoBox DoBox下载 下载地址:http://www.wxzzz.com/?id=141 最新版本: ...
- SQLServer------如何让标识列重新开始计算
方法: DBCC CHECKIDENT (表名, RESEED, )
- web服务器http.server 【python】
参考博客: http://lxneng.iteye.com/blog/492063 http://www.cnblogs.com/itech/archive/2011/12/31/2308697.ht ...
- poj_2352 Treap
题目大意 对于二维平面上的n个点,给出点的坐标.定义一个点A覆盖的点的个数为满足以下条件的点B的个数:点B的x <= 点A的x坐标,点B的y坐标 <= 点A的y坐标. 给出N个点的 ...
- LeetCode——Best Time to Buy and Sell Stock IV
Description: Say you have an array for which the ith element is the price of a given stock on day i. ...
- BOM history对象
history对象的三个可用方法和一个属性 back();后退 forward();前进 go(n);跳到第几个页面,负数为后退,正数为前进 length属性,获取缓存的页面的数量 安全性考虑,his ...
- Android 动画fillAfter和fillBefore
fillBefore是指动画结束时画面停留在此动画的第一帧; fillAfter是指动画结束是画面停留在此动画的最后一帧. Java代码设置如下: /*****动画结束时,停留在最后一帧******* ...
- web移动端一些常用知识
1.去掉 a,input 在移动端浏览器中的默认样式(半透明灰色遮罩阴影) a,button,input,optgroup,select,textarea { -webkit-tap-highligh ...
- 【BZOJ3529】[Sdoi2014]数表 莫比乌斯反演+树状数组
[BZOJ3529][Sdoi2014]数表 Description 有一张N×m的数表,其第i行第j列(1 < =i < =礼,1 < =j < =m)的数值为能同时整除i和 ...
- [WIFI] WIFI 破解(初级)
话不多说,先来看看字典破解 wpa2 的效果 =================================== ========================================= ...