Color the ball HDU - 1556 _差分
N名同学拍成一排,编号为1,2,3,4 …… N。现在有一位老师需要检查所有同学的出勤情况,他会进行点名,每次给出两个数a,b,并且保证a小于等于b,这个区间内的所有同学都会被点名一次,老师会进行N次点名,请问点名结束后,每位同学被点名的总次数是多少
Input
每个测试实例第一行为一个整数N,(N <= 100000).
接下来的N行,每行包括2个整数a b(1 <= a <= b <= N)。
当N = 0,输入结束。
Output
每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。
Input Sample
3
1 1
2 2
3 3
3
1 1
1 2
1 3
0
Output Sample
1 1 1
3 2 1
分析
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10,INF=0x3f3f3f3f;
int n,m,a,b,d[N];
int main(){
while(cin>>n && n){
memset(d,0,sizeof(d));
m=n; while (m--){
cin>>a>>b;
d[a] ++;
d[b+1] --;
}
for(int i=1; i<=n; i++) d[i]+=d[i-1];
for(int i=1; i<=n; i++) cout<<d[i]<<" \n"[i==n];
}
}
Color the ball HDU - 1556 _差分的更多相关文章
- A - Color the ball HDU - 1556 (差分数组+前缀和)
思路等引自博客 https://blog.csdn.net/johnwayne0317/article/details/84928568 对数组a[7]: a[0]=1; = d[0] a[1]=1; ...
- Color the ball HDU - 1556 (非线段树做法)
题意:在1到n的气球中,在不同的区域中涂颜色,问每个气球涂几次. #include<cstdio>int num[100010];int main(){ int n, x, y;; whi ...
- Color the ball HDU - 1556 (线段树)
思路:线段树,区间更新 #include<iostream> #include<vector> #include<string> #include<cmath ...
- 树状数组模板--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 ...
- 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 (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- 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 ...
- hdu 1556 Color the ball(区间更新,单点求值)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- Excel工具(批量生成txt)
Sub txt() Dim i, j, arr(), brr(), myRow, myCol arr = Sheet1.UsedRange myRow = UBound(arr, 1) myCol = ...
- Unity ARCore动态增加识别图
项目需要,有两点要求说明一下 1.如果你的图片是下载生成的,那没什么问题 2.如果你的识别图是存储在APK包里的话需要调整图片属性: 代码如下: using QFramework; using Sys ...
- 【Shell】DBeaver Enterprise Edition 5.1.1 Download
DBeaver Enterprise Edition 5.1.1 Download mkdir -p /opt/downloads/dbeaver/dbeaver-ee-5.1.1 mkdir -p ...
- redis 持久化之RDB和AOF的区别
持久化之RDB 定义:在指定的时间间隔内生成数据集的时间点快照 RDB 的优点: 1.RDB 是一个非常紧凑的文件 它保存了 Redis 在某个时间点上的数据集. 这种文件非常适合用于进行备份: 比如 ...
- unity 阿拉伯数字转中文汉字
直接调用即可 代码如下: using System; using System.Collections; using System.Collections.Generic; using System. ...
- mac使用expect登录跳板机后的机器
两个文档 #!/usr/bin/expect -f #连接文件名字记录 set ip [lindex $argv 0] catch {spawn ssh 1.1.1.1}## ip地址换成自己的 ex ...
- JAVA流程控制(查漏补缺)
JAVA流程控制(查漏补缺) 目录 JAVA流程控制(查漏补缺) if 判断 switch多重选择 编译检查 for循环 for each break和continue if 判断 要判断引用类型的变 ...
- 常用的js方法
1. 声明和初始化数组 我们可以使用默认值(如"".null或 )初始化特定大小的数组0.您可能已经将这些用于一维数组,但如何初始化二维数组/矩阵呢? const array = ...
- 使用Wireshark完成实验3-IP
1.使用Wireshark打开ip-ethereal-trace-1,如图 电脑IP地址为192.168.1.102 2.如图,IP包头中上层协议字段的值为1,代表为ICMP 3.如图,IP头中有20 ...
- COMMON_FUNC_SPLIT_STRING
void SplitString(const std::string& s, std::vector<std::string>& v, const std::string& ...