Color the ball(差分数组)
Input每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 <= a <= b <= N)。
当N = 0,输入结束。Output每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。Sample Input
3
1 1
2 2
3 3
3
1 1
1 2
1 3
0
Sample Output
1 1 1
3 2 1
差分数组和前缀和是互逆的
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
inline int read() {int x=,f=;char c=getchar();while(c!='-'&&(c<''||c>''))c=getchar();if(c=='-')f=-,c=getchar();while(c>=''&&c<='')x=x*+c-'',c=getchar();return f*x;}
typedef long long ll;
const int maxn=1e6+;
const int M=1e7+;
const int INF=0x3f3f3f3f;
int a[maxn];
int b[maxn];
int main()
{
int n;
while(~scanf("%d",&n)){
if(n==){
break;
}
memset(a,,sizeof(a));
memset(b,,sizeof(b));
int x,y;
for(int i=;i<=n;i++){
cin>>x>>y;
b[x]++;
b[y+]--;
}
for(int i=;i<=n;i++){
a[i]=a[i-]+b[i];
}
for(int i=;i<n;i++){
printf("%d ",a[i]);
}
printf("%d\n",a[n]);
}
return ;
}
Color the ball(差分数组)的更多相关文章
- HDU1556 Color the ball(差分数组)题解
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 1556 Color the ball【差分数组裸题/模板】
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一 ...
- A - Color the ball HDU - 1556 (差分数组+前缀和)
思路等引自博客 https://blog.csdn.net/johnwayne0317/article/details/84928568 对数组a[7]: a[0]=1; = d[0] a[1]=1; ...
- HDU1556 Color the ball & 牛客 contest 135-I 区间 [差分标记]
一.差分标记介绍 差分标记用来解决针对区间(修改-查询)的问题,复杂度比线段树要更低.推荐这个博客. 例如,给数组中处于某个区间的数进行加减操作,然后查询某个位置上数的变化值. 二.HDU1556 C ...
- 树状数组模板--Color the ball
Color the ball HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电 ...
- 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(树状数组+线段树+二分)
Color the ball Time Limit : 9000/3000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- 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 (线段树和差分数组两种解法)
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一 ...
随机推荐
- 高端OLED电视成行业突破口,苏宁助力显示技术市场迭代
编辑 | 于斌 出品 | 于见(mpyujian) 在电商与线上渠道越来越占据举足轻重地位的年代,电商平台巨头们越来越有底气喊出"推动行业技术升级"的口号.的确,再好的技术升级也需 ...
- 是未来还是“有毒”?紧抓球鞋风口的毒APP机遇与危机并存
编辑 | 于斌 出品 | 于见(mpyujian) 新一代的"潮流"之风正在席卷新生代消费市场,从去年开始,国内二手球鞋交易领域突然开始火爆,大有成为新一轮"风口&quo ...
- Java基本语法--变量
本篇博客主要介绍了Java基本语法中变量(variable)d的使用,变量是指内存中的一个存储区域,用于在内存中保存数据,在该区域的数据可以在同一类型范围内不断变化.变量是程序中最基本的存储单元.包含 ...
- leetcode 198 House Robber I
function rob(nums) { if(!nums || nums.length === 0) { return 0; } else if(nums.length < 2){ retur ...
- Python_包
包 包是一种通过使用‘.模块名’来组织python模块名称空间的方式. 1. 无论是import形式还是from...import形式,凡是在导入语句中(而不是在使用时)遇到带点的,都要第一时间提高警 ...
- DisplayNameFor()方法的工作原理
DisplayNameFor()方法的工作原理原创Peter Yelnav 最后发布于2018-11-23 11:09:51 阅读数 1308 收藏展开最近研究了一下ASP.NET MVC,困惑于视图 ...
- Html基本控件介绍
1. <input>标签<input> 标签用于搜集用户信息. 1.1 type属性根据不同的 type 属性值,输入字段拥有很多种形式.可以是文本字段.复选框.掩码后的文本控 ...
- wamp修改MySQL密码
wamp默认密码为空 用户名为root: 左击wamp绿色小图标,打开phpMyAdmin ->执行 ->账号 ->找到用户名为root的修改权限&&点击修改权限 - ...
- 解决mailx发邮件报错:esmtp-server: 504 5.7.4 Unrecognized authentication type [HK2PR02CA0167.apcprd02.prod.outlook.com] "/root/dead.letter" 11/302 . . . message not sent.
报错信息: esmtp-server: 504 5.7.4 Unrecognized authentication type [HK2PR02CA0167.apcprd02.prod.outlook. ...
- Custom LED Keychain, Small And Surefire Gifts
The LED Keychain makes it easy for people to carry their keys with them and carry them with th ...