HDUOJ -----Color the ball
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7497 Accepted Submission(s): 3865
当N = 0,输入结束。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define maxn 100000
int aa[maxn+];
int nn;
int lowbit(int x)
{
return x&(-x);
}
void ope(int x,int val)
{
while(x<=nn)
{
aa[x]+=val;
x+=lowbit(x);
}
}
int sum(int x)
{
int ans=;
while(x>)
{
ans+=aa[x];
x-=lowbit(x);
}
return ans;
}
int main()
{
int i,a,b;
while(scanf("%d",&nn),nn)
{
memset(aa,,sizeof(aa));
for(i=;i<nn;i++)
{
scanf("%d%d",&a,&b);
ope(a,);
ope(b+,-);
}
printf("%d",sum());
for(i=;i<=nn;i++)
printf(" %d",sum(i));
putchar();
}
return ;
}
HDUOJ -----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 ...
随机推荐
- 《mahout实战》
<mahout实战> 基本信息 原书名:Mahout in action 作者: (美)Sean Owen Robin Anil Ted Dunning Ellen Fr ...
- C柔性数组
柔性数组成员 柔性数组 .允许结构中包含一个大小可变的数组,sizeof返回的这种结构大小不包括柔性数组的内存. .包含柔性数组成员的结构要使用malloc()函数进行内存的动态分配.分配的内存大于结 ...
- 【BZOJ】【3083】遥远的国度
树链剖分/dfs序 其实过了[BZOJ][4034][HAOI2015]T2以后就好搞了…… 链修改+子树查询+换根 其实静态树的换根直接树链剖分就可以搞了…… 因为其实只有一样变了:子树 如果roo ...
- Spring 事务模板
最近项目开发中需要用到单机事务,因为项目中使用了Spring和Mybatis框架,所以通过Spring来进行事务的管理,并且记录一下事务配置的过程 第一步:配置DataSource <!-- 发 ...
- python内置函数和魔法函数
内置方法:Python中声明每一个类系统都会加上一些默认内置方法,提供给系统调用该类的对象时使用.比如需要实例化一个对象时,需要调用该类的init方法:使用print去打印一个类时,其实调用的是str ...
- 使用Spring Security和OAuth2实现RESTful服务安全认证
这篇教程是展示如何设置一个OAuth2服务来保护REST资源. 源代码下载github. (https://github.com/iainporter/oauth2-provider)你能下载这个源码 ...
- Web开发者不容错过的10段CSS代码
Web开发技术每年都在革新,浏览器已逐渐支持CSS3特性,并且网站设计师和前端开发者普遍采用这种新技术进行设计与开发.但仍然有一些开发者迷恋着一些CSS2代码. 本文将分享20段非常专业的CSS2/C ...
- [LeetCode] Distinct Subsequences [29]
题目 Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequen ...
- Sublime Text自定义插入当前时间的插件
很奇怪为什么强大的Sublime编辑器为什么没有添加当前时间的快捷键,不过还好Sublime可以通过自定义插件的方式来实现任何你想要的效果 1. 创建插件: Tools → New Plugi ...
- javascript进行遍历
javascript进行遍历 <!doctype html> <html lang="en"> <head> <meta charset= ...