#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<deque>
#include<iomanip>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<fstream>
#include<memory>
#include<list>
#include<string>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MAXN 100001
#define L 31
#define INF 1000000009
#define eps 0.00000001
struct node
{
LL l, r, data;
}T[MAXN*+];
LL n,a[MAXN];
LL Query(LL p, LL k)
{
if (T[p].l == T[p].r)
return T[p].data;
LL mid = (T[p].l + T[p].r) >> ;
LL sum = T[p].data;
if (k <= mid)
sum += Query(p << , k);
else
sum += Query(p << | , k);
return sum;
}
void Build(LL p, LL l, LL r)
{
T[p].l = l, T[p].r = r, T[p].data = ;
if (l == r)
{
T[p].data = a[l];
return;
}
LL mid = (l + r) >> ;
Build(p << , l, mid);
Build(p << | , mid + , r);
}
void Insert(LL p, LL l, LL r, LL num)
{
//cout << p << ' ' << l << ' ' << r << ' ' << num << endl;
if (l <= T[p].l&&r >= T[p].r)
{
T[p].data += num;
return;
}
LL mid = (T[p].l + T[p].r) / ;
if (r <= mid)
Insert(p << , l, r, num);
else if (l > mid)
Insert(p << | , l, r, num);
else
{
Insert(p << , l, mid, num);
Insert(p << | , mid + , r, num);
}
}
int main()
{
while (scanf("%lld", &n), n)
{
LL t1, t2;
memset(a, , sizeof(a));
Build(, , n);
for (LL i = ; i <= n; i++)
{
scanf("%lld%lld", &t1, &t2);
Insert(, t1, t2, );
}
for (LL i = ; i <= n; i++)
{
if (i>) printf(" ");
printf("%lld", Query(, i));
}
printf("\n");
}
return ;
}

Online Judge Online Exercise Online Teaching Online Contests Exercise Author
F.A.Q
Hand In Hand
Online Acmers
Forum |Discuss
Statistical Charts
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
Virtual Contests
  DIY |Web-DIY beta
Recent Contests
 

Color the ball

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 19857    Accepted Submission(s): 9901

Problem Description
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?
 
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
 
Author
8600

Color the ball 线段树 区间更新但点查询的更多相关文章

  1. HDU.1556 Color the ball (线段树 区间更新 单点查询)

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

  2. HDU 1556 Color the ball(线段树区间更新)

    Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...

  3. hdu 1556 Color the ball 线段树 区间更新

    水一下 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 ...

  4. ZOJ - 1610 Count the Colors(线段树区间更新,单点查询)

    1.给了每条线段的颜色,存在颜色覆盖,求表面上能够看到的颜色种类以及每种颜色的段数. 2.线段树区间更新,单点查询. 但是有点细节,比如: 输入: 2 0 1 1 2 3 1 输出: 1 2 这种情况 ...

  5. 2017 Wuhan University Programming Contest (Online Round) D. Events,线段树区间更新+最值查询!

    D. Events 线段树区间更新查询区间历史最小值,看似很简单的题意写了两天才写出来. 题意:n个数,Q次操作,每次操作对一个区间[l,r]的数同时加上C,然后输出这段区间的历史最小值. 思路:在线 ...

  6. hdu1556Color the ball线段树区间更新

    题目链接 线段树区间更新更新一段区间,在更新区间的过程中,区间被分成几段,每一段的左右界限刚好是一个节点的tree[node].left和tree[node].right(如果不是继续分,直到是为止) ...

  7. hdu 1556 Color the ball(线段树区间维护+单点求值)

    传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/3276 ...

  8. 2015 UESTC 数据结构专题A题 秋实大哥与小朋友 线段树 区间更新,单点查询,离散化

    秋实大哥与小朋友 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Desc ...

  9. hdu1556 Color the ball 线段树区间染色问题

    都是老套路了,如果n=5,要把区间[1,4]染色,可以递归去染区间[1,3]和区间[4,4],如果区间相等就自加,不相等继续递归寻找对应区间. 打印结果时,把所有到达叶节点包含i的区间值相加,就是最后 ...

随机推荐

  1. PCB 所建不凡 AWS 技术峰会2018 • 深圳站 2018.9.20

    在去[AWS 技术峰会2018 • 深圳站]之提前并没有AWS提前做功课,主要PCB这行业基本自己搭服务器搭应用,不会买云服务器.由于没用过企业级的云服务器,对云这方面还是了解还是非常有限的. 市面上 ...

  2. Three Kingdoms(优先队列+bfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=3442 题意:ABCD有各自的攻击力与攻击范围,刘备只能走"C"与".", ...

  3. mysql select 操作优先级

    单表查询操作 select filed1,filed2... form table where ... group by ... having .... order by ... limit ... ...

  4. Java使用Cipher类实现加密,包括DES,DES3,AES和RSA加密

    一.先看一个简单加密,解密实现 1.1 加密 /** * content: 加密内容 * slatKey: 加密的盐,16位字符串 * vectorKey: 加密的向量,16位字符串 */ publi ...

  5. URI、URL、请求、响应、常见状态代码

    URI:路径(统一资源标识符,包括本地地址和网络地址) URL是URI的一种子路径, URI范围比URL范围广. URL (Uniform Resource Locator,统一全球资源定位符): 通 ...

  6. python 之 sqlite3

    # -*- coding: utf-8 -*- ''' 创建数据库日志,三列为时间 身份证号和备注名''' import os import sys import sqlite3 import dat ...

  7. JS——高级各行换色

    1.获取tbody下的子元素 2.注册鼠标覆盖事件时存储当时的背景颜色,注册鼠标离开事件时把存储的颜色赋值注册事件对象 <!DOCTYPE html> <html> <h ...

  8. JS——数组

    concat:连接两个或多个数组,返回被连接数组的一个副本. var arr1 = [12, "你好", "哈哈"] var arr2 = [12, " ...

  9. ProE复杂曲线方程:Python Matplotlib 版本代码(L系统,吸引子和分形)

    对生长自动机的研究由来已久,并在计算机科学等众多学科中,使用元胞自动机的概念,用于生长模拟.而复杂花纹的生成,则可以通过重写一定的生长规则,使用生成式来模拟自然纹理.当然,很多纹理是由人本身设计的,其 ...

  10. spark的体系结构

    spark的体系结构 1.客户端(Driver Program) 需要构建一个对象,核心是sc(SparkContext) 以应用程序为例:链接本地 //new conf val conf=new S ...