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 ...
随机推荐
- java解析页面包jsoup
http://www.open-open.com/jsoup/parsing-a-document.htm jsoup: Java HTML Parser jsoup is a Java librar ...
- mybatis logback打印sql
<?xml version="1.0" encoding="UTF-8" ?><configuration> <contextNa ...
- hdu4010 Query On The Trees
Problem Description We have met so many problems on the tree, so today we will have a query problem ...
- 使用iScroll和photoswipe写手机浏览图片的插件的几点经验
首先,当我知道我得到一个任务需要写一个在手机上能浏览图片的插件时,我第一想到了iScroll.它的左右滑动,上下滑动的效果在安卓手机上也能让用户有良好的体验,自己写也能方便控制. 我的需求是,插件要能 ...
- Java注解的简单了解
部分信息来自<Thinking In Java> 注解也成为元数据.什么是元数据?就是“关于数据的数据” 注解为我们在代码中添加信息提供了一种形式化的方法,使我们可以在稍后某个时刻非常方便 ...
- checkbox 全选/取消
<html><script language=javascript>function selectAll(){var a = document.getElementsByTag ...
- Python多进程使用
[Python之旅]第六篇(六):Python多进程使用 香飘叶子 2016-05-10 10:57:50 浏览190 评论0 python 多进程 多进程通信 摘要: 关于进程与线程的对比, ...
- .NET通信中的同步和异步处理
同步与异步的概念: .NET中的通信数据处理有同步和异步之分,我理解的同步过程是接收端接收数据,如果数据没有过来,就一直等着(阻塞过程),直到有数据传送过来可以接收,接下来程序才继续向下进行:异步过程 ...
- access的时间相关的查询
string sql = "select * from CONCURRENCY WHERE CONCURRENCY.DATE_FLAG BETWEEN cdate('2013-11-1', ...
- 关于 rem 作为单位设置大小
rem是相对长度单位.相对于根元素(即html元素)font-size计算值的倍数htm{font-size: 62.5%;}根元素(html)先设置一个font-size,一般情况下为了容易计算re ...