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 ... 
随机推荐
- Object.defineProperty(定义试添加json对象的属性)
			<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ... 
- nginx配置普通server
			1 新建conf并添加如下: server { listen 2222; #listen.server_name这些正常配置 listen [::]:2222; server_name localho ... 
- 超级详细的Vue安装与配置教程
			原文: https://www.jb51.net/article/251371.htm 超级详细的Vue安装与配置教程 Vue web前端三大主流框架之一,是一套用于构建用户界面的渐进式框架,下面 ... 
- java读取apk、ipa包名、版本名、版本号等信息
			package com.gymexpress.exerciseservice.controller;import com.gymexpress.commonmodel.controller.BaseC ... 
- MTSC2021上海站PPT 分享
- Stream流常用API
			文档 https://www.runoob.com/java/java8-streams.html JDK8 Stream API: https://docs.oracle.com/javase/8/ ... 
- 使用 PSAPI 库枚举进程 EnumProcesses()函数
			使用 PSAPI 库枚举进程 在 Windows NT 中,创建进程列表使用 PSAPI 函数,这些函数在 PSAPI.DLL 中.这个文件是随 Platform SDK 一起分发的: 使用这个库所需 ... 
- Vmware-workstation - Centos8.0扩容磁盘空间  /  目录
			1. 软件版本 vmware workstation 15 pro 虚拟机: centos8.0 2.将虚拟机关机选择扩容到多大 3. 进入操作系统,执行lsblk查看sda盘的情况.下图所示,需要 ... 
- UPPER VSCODE
- win10 + emacs + sml
			1.官网下载sml编译器是smi安装包,安装结束之后把bin文件夹放到环境变量Path中 2.下载emacs压缩包,直接解压 3.emacs中alt+x,输入package-list 然后选择sml- ... 
