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 ...
随机推荐
- fireworks切图
下载安装完成后打开软件 打开一张图片 首选参数的撤销次数改成999 按住空格键 鼠标会变成小手的形状 这时候可以拖拽图像 找到切片工具 记住缩放比例的快捷键 ctrl+空格 放大某个区域 切的时候按住 ...
- Maven War包 POM配置文件
如何为你的Web程序(war包设定配置文件) 约定 http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering ...
- Socket无连接简单实例
使用无连接的套接字,我们能够在自我包含的数据包里发送消息,采用独立的读函数读取消息,读取的消息是使用独立的发送函数发送的.但是UDP数据包不能保证可靠传输,存在许多的因素,比如网络繁忙等等,都有可能阻 ...
- Oracle Apex 有用笔记系列 2 - 文件上传管理
1. 页面设计 页面A有若干region, 当中一个region用于文件列表管理(包含显示,下载.删除).如图A. 在页面A有一button,点击它会调用页面B,页面B负责文件上传.如图B. 图A 图 ...
- NodeJS-003-自动刷新
修改index.js之后,发现刷新浏览器,没有任何更改,需要关闭应用重新启动. 为了避免每次修改代码后要自动重启.通过安装supervisor来监控代码修改. 安装:npm install -g su ...
- complex()
complex() 用于将一个对象转换为复数 In [1]: complex(123) # 将整数转换为复数 Out[1]: (123+0j) In [2]: complex(') # 将纯数字的字符 ...
- 如何连接 MySQL
操作如下: [root@localhost ~]$ mysql -uroot -p' # 本地连接 MySQL 服务 [root@localhost ~]$ mysql -uroot -p' -h19 ...
- CentOS5.5环境下布署LVS+keepalived
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://kerry.blog.51cto.com/172631/401253 #!/bin ...
- Effective C++ —— 构造/析构/赋值运算(二)
条款05 : 了解C++默默编写并调用哪些函数 编译器可以暗自为class创建default构造函数.copy构造函数.copy assignment操作符,以及析构函数. 1. default构造函 ...
- MQTT的学习研究(四)moquette-mqtt 的使用之mqtt Blocking API客户端订阅并接收主题信息
在上面两篇关于mqtt的broker的启动和mqtt的服务端发布主题信息之后,我们客户端需要订阅相关的信息并接收相关的主题信息. package com.etrip.mqtt; import java ...