Color the ball
hdu1556:http://acm.hdu.edu.cn/showproblem.php?pid=1556
题意:中文题。
题解:这一题当然可以直接用线段树来打,但是最近在学树状数组,所以用树状数组打了。树状数组有两种更新和求和的方式。1是向上更新,向下查询。2是向下更新,向上查询。第二种可以用来区间更新。例如更新(u,v,num),先update(v,num),然后update(u-1,-num);getsum(i)得到的就是第i个数的值。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 1000000
using namespace std;
int c[MAXN];
int n,u,v;;
int lowbit(int x){
return x&(-x);
}
void add(int x,int num){
while(x>=){
c[x]+=num;
x-=lowbit(x);
}
}
int getsum(int x){
int sum=;
while(x<=n){
sum+=c[x];
x+=lowbit(x);
}
return sum;
}
int main(){
while(~scanf("%d",&n)&&n){
memset(c,,sizeof(c));
for(int i=;i<=n;i++){
scanf("%d%d",&u,&v);
add(v,);
add(u-,-);
}
for(int i=;i<n;i++)
printf("%d ",getsum(i));
printf("%d\n",getsum(n));
}
}
Color the ball的更多相关文章
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Color the Ball[HDU1199]
Color the Ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 线段树--Color the ball(多次染色问题)
K - Color the ball Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- hdu 1199 Color the Ball
http://acm.hdu.edu.cn/showproblem.php?pid=1199 Color the Ball Time Limit: 2000/1000 MS (Java/Others) ...
- Color the ball HDOJ--1556
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdoj 1556 Color the ball【线段树区间更新】
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1199 Color the Ball(离散化线段树)
Color the Ball Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Color the ball(树状数组+线段树+二分)
Color the ball Time Limit : 9000/3000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
随机推荐
- git上解决代码冲突
1.切换到master: git co master 2.拉最新代码:git pull origin master 3.删掉多余符号 4.切换到提交的分支:git br Txxxx 5.合并:git ...
- Java里的IO流里的FileInputStream 的读取并在前打印行数!
大家好!!新人求罩! import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException ...
- Qt Quick 事件处理之信号与槽
前面两篇文章<QML 语言基础>和<Qt Quick 简单教程>中我们介绍了 QML 语言的基本的语法和 Qt Quick 的常见元素,亲们,通过这两篇文章,您应该已经能够完毕 ...
- Error parsing XML: not well-formed (invalid token) 报错+R文件消失解决的方法
xml报错: 这个xml文件上右键source ->format 注意:res下的文件名称不能大写 R文件消失: 在攻克了其它问题的情况下(或者其它问题还没解决先凝视掉) 手动删除gen pro ...
- oracle日期时间函数总结
常常写 sql 的同学应该会接触到一些 oracle 的日期时间函数, 比如: 財务软件或者人力资源软件须要依照每年, 每季度, 每月, 甚至每一个星期来进行统计. 今天闲来没事, 特意从网上整理了一 ...
- Android 开源项目android-open-project解析之(三) ScrollView,TimeView,TipView,FlipView
九.ScrollView Discrollview 支持滚动时Item淡入淡出,平移,缩放效果的ScrollView 项目地址:https://github.com/flavienlaurent/di ...
- 开启.htaccess重写之前先来看看mod_rewrite(转)
Apache的Mode Rewrite模块提供了一个基于正则表达式分析器的重写引擎来实时重写URL请求.在大多数情况下,它和.htaccess文件配合使用.就是说,.htaccess文件的一个主要功能 ...
- 第四篇:SQL
前言 确实,关于SQL的学习资料,各类文档在网上到处都是.但它们绝大多数的出发点都局限在旧有关系数据库里,内容近乎千篇一律.而在当今大数据的浪潮下,SQL早就被赋予了新的责任和意义. 本篇中,笔者将结 ...
- 4道过滤菜鸟的iOS面试题
网上已经有很多针对各种知识点的面试题,面试时有些人未必真正理解也能通过背题看上去很懂.我自己总结了4道面试题,好快速的判断这个人是否是一个合格的工程师,欢迎大家点评. 1.struct和class的区 ...
- 尚未解决的intellij问题:补充措施
2016-12-06 遇到问题 D:\software\apache-tomcat-7.0.57\bin\catalina.bat run [2016-12-06 09:54:52,342] Arti ...