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 _差分的更多相关文章

  1. A - Color the ball HDU - 1556 (差分数组+前缀和)

    思路等引自博客 https://blog.csdn.net/johnwayne0317/article/details/84928568 对数组a[7]: a[0]=1; = d[0] a[1]=1; ...

  2. Color the ball HDU - 1556 (非线段树做法)

    题意:在1到n的气球中,在不同的区域中涂颜色,问每个气球涂几次. #include<cstdio>int num[100010];int main(){ int n, x, y;; whi ...

  3. Color the ball HDU - 1556 (线段树)

    思路:线段树,区间更新 #include<iostream> #include<vector> #include<string> #include<cmath ...

  4. 树状数组模板--Color the ball

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

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

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

  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 (线段树 区间更新 单点查询)

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

  8. HDU 1556 Color the ball (数状数组)

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

  9. 线段树(求单结点) hdu 1556 Color the ball

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

  10. hdu 1556 Color the ball(区间更新,单点求值)

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

随机推荐

  1. SpringBoot运行就停止

    检查下是不是没有引入springboot-starter-web依赖 <dependency> <groupId>org.springframework.boot</gr ...

  2. 获取Java运行环境信息

    设备相关信息 获取设备名称 import java.net.InetAddress; import java.net.UnknownHostException; try { InetAddress l ...

  3. JDK下载很慢

    方法1.直接百度jdk镜像,搜到华为镜像:https://repo.huaweicloud.com/java/jdk/ 方法2.到官网拷贝下载的url:https://download.oracle. ...

  4. VSCode 修改终端显示字体 字体间隔过大

    参考链接: https://code84.com/172442.html

  5. 深入理解JVM 学习笔记2

    Java内存区域 在执行java程序的过程中JVM会把它管理的内存划分为多个不同的数据区域. 根据<Java 虚拟机规范 SE7版>的规定,Java 虚拟机所管理的内存将会包括以下几个运行 ...

  6. 处理Android的物理后退按钮

    在文章.聊天.联系.相册四个页面时,用户点击Android 物理键返回,需要直接退出程序.我这里处理很简单,直接使用react-navigation的属性backbehavior就很快的解决了. &l ...

  7. (0619) 电脑 传 ipad

  8. ptyhon基础课程_2

    10 输入 # 例一 user_name = input ("请输入姓名:") message = user_name + "shaobing" print ( ...

  9. 3 - 标准数据加密(DES)及其备选

    标准数据加密(DES)及其备选 我的博客 原书:<Understanding Cryptography: A Text book for Students and Practitioners&g ...

  10. 简单理解gqrx是什么

    gqrx:Gqrx是一个基于gnuradio和Qt架构,开发的一个开源的SDR接收机的应用.下图是他的一个运行界面: gnu radio GNU Radio是一个自由软件开发工具包,提供实现软件无线电 ...