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 ...
随机推荐
- Java程序员职业规划
Java 程序员职业规划 无论你是学习了 Java 即将进入企业工作,还是已经踏入了工作岗位的程序员.但是面对层出不穷的新技术,激增的就业压力,不断分化的开发角色,再加上 IT 发展的不明确,做出职业 ...
- laravel 模版引擎使用
laravel 模版引擎以 @标签 开头,以 @end标签 结尾,常用有 foreach foreachelse if for while等 1)foreach 和 foreachelse 差不到,区 ...
- set集合操作【python】
set集合操作包括: >>> x=set("123defj89") >>> y=set("ab34e6jh9") >& ...
- org.apache.activemq.transport.InactivityIOException: Cannot send, channel has already failed
项目是使用activeMQ 发布订阅的模式,在本地测试正常,但是 放到服务器上出现这个错误: org.apache.activemq.transport.InactivityIOException: ...
- oracle dblink结合同义词的用法 PLS-00352:无法访问另一数据库
我从源库导出数据PCK报错如下:
- Unity3d 手机屏幕自动适配
我提到手机自动适配的一个方法中:postion和Scale,“比例”概念适配手机.原始资源是480*800 经过实际项目考验,个人感觉: 1,UICamera是自动适配分辨率,UI上也是拉伸.放大UI ...
- Activity、Window和View三者间的关系有一定的见解
一.简述如何将Activity展现在手机上 Tips: Activity本身是没办法处理显示什么控件(view)的,是通过PhoneWindow进行显示的 换句话说:activity就是在造Phone ...
- windows下配置VisualSVN Server服务器
下载安装文件: 服务端安装文件:VisualSVN-Server-1.6.2 客户端安装文件:TortoiseSVN-1.5.5.14361-win32-svn-1.5.4 上面是我使用的版本. 在V ...
- [020]Sencha Ext JS 6.0使用教程2
本节主要以典型例子介绍如何用Sencha Ext JS6.0进行项目开发 入门阶段总是比较难的,掌握了基本操作步骤,使用方法,架构思维,开发起来还是满顺利,开心的,自己又能掌握一门新技术,又能进步,主 ...
- tomcat日志保存在哪里?
tomcat目录下的logs文件夹下.有个catalina.20xx-xx-xx.log