题意:给出n个区间,每次给这个区间里面的数加1,询问单点的值

一维的区间更新,单点查询,还是那篇论文里面讲了的

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int n;
int c[maxn]; int lowbit(int x){ return x &(-x);} int sum(int x){
int ret=;
while(x>){
ret+=c[x];x-=lowbit(x);
}
return ret;
} void add(int x,int d){
while(x<=n){
c[x]+=d; x+=lowbit(x);
}
} int main(){
while(scanf("%d",&n) != EOF){
if(n == ) break;
memset(c,,sizeof(c));
for(int i=;i<=n;i++){
int a,b;
scanf("%d %d",&a,&b);
add(a,);add(b+,-);
}
printf("%d",sum());
for(int i=;i <= n;i++)
printf(" %d",sum(i));
printf("\n");
}
return ;
}

HDU 1556 Color the ball【树状数组】的更多相关文章

  1. HDOJ/HDU 1556 Color the ball(树状数组)

    Problem Description N个气球排成一排,从左到右依次编号为1,2,3-.N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从 ...

  2. HDU 1556 Color the ball (树状数组区间更新)

    水题,练习一下树状数组实现区间更新. 对于每个区间,区间左端点+1,右端点的后一位-1,查询每个位置的覆盖次数 #include <cstdio> #include <cstring ...

  3. HDU 1556 Color the ball 树状数组 题解

    Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动 ...

  4. Color the ball(树状数组+线段树+二分)

    Color the ball Time Limit : 9000/3000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  5. HDU 1556 Color the ball【差分数组裸题/模板】

    N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一 ...

  6. hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  7. hdu 1556:Color the ball(线段树,区间更新,经典题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  8. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  9. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  10. hdu 5517 Triple(二维树状数组)

    Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

随机推荐

  1. Centos7 minimal 系列之Redis共享sessionid(七)

    这一章节的内容就当看看,只是个人理解,我想应该是有误的. 一.SessionId sessionid是一个会话的key,浏览器第一次访问服务器会在服务器端生成一个session,有一个sessioni ...

  2. JQuery事件绑定,bind与on区别

    jquery事件绑定bind:向匹配元素添加一个或多个事件处理器 $(selector).bind("click",data,function); live:向当前或未来的匹配元素 ...

  3. python pip fatal error in launcher unable to create process using

    用pip安装一个包,不知道为啥,就报了这个错误:python pip fatal error in launcher unable to create process using “”   百度了一下 ...

  4. 注解实战BeforeMethed和afterMethed

    package com.course.testng;import org.testng.annotations.AfterMethod;import org.testng.annotations.Be ...

  5. [USACO07OPEN]Catch That Cow

    题目:洛谷P1588.HDU2717 题目大意:有一个人在点$n$,一头牛在点$k$,人每秒能从$x$移动到点$x+1$.$x-1$.$2x$,牛不会动,求最少多少秒后人能移动到牛所在的$k$. 思路 ...

  6. java SSM多操作注解回滚

    在业务操作时难免会遇到一个业务多操作,会用到事物回滚这里写了一个简单的多操作失败事物回滚案例 在这之前你需要在你的applicationContext-mybatis.xml中配置: <!-- ...

  7. java实现随机数的生成

    一,课程中的动手动脑的问题 1,编写一个方法,使用以上算法生成指定数目的随机整数. public void suiJiShu(){ Scanner input=new Scanner(System.i ...

  8. Linux系统串口接收数据编

    http://blog.csdn.net/bg2bkk/article/details/8668576 之前基于IBM deveplopworks社区的代码,做了串口初始化和发送的程序,今天在此基础上 ...

  9. static和extern的作用域--题目

    #include <stdio.h> ; int main(void) { , sum = , count = ; ,count++) // count = 2 { ; count++; ...

  10. Java基础学习总结(57)——Jrebel插件热部署

    JavaEE开发环境下,Tomcat对热布署的支持还是比较弱,致使开发过程中浪费大量时间在重启服务上.胖先生讨厌来来回回的折腾,所以想看看有没有实时的编译,发现Jrebel的插件付费软件,它对热布署的 ...