Color the ball 线段树 区间更新但点查询
#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 ;
}
![]() |
||||||||||
|
||||||||||
Color the ballTime Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 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 线段树 区间更新但点查询的更多相关文章
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- hdu 1556 Color the ball 线段树 区间更新
水一下 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 ...
- ZOJ - 1610 Count the Colors(线段树区间更新,单点查询)
1.给了每条线段的颜色,存在颜色覆盖,求表面上能够看到的颜色种类以及每种颜色的段数. 2.线段树区间更新,单点查询. 但是有点细节,比如: 输入: 2 0 1 1 2 3 1 输出: 1 2 这种情况 ...
- 2017 Wuhan University Programming Contest (Online Round) D. Events,线段树区间更新+最值查询!
D. Events 线段树区间更新查询区间历史最小值,看似很简单的题意写了两天才写出来. 题意:n个数,Q次操作,每次操作对一个区间[l,r]的数同时加上C,然后输出这段区间的历史最小值. 思路:在线 ...
- hdu1556Color the ball线段树区间更新
题目链接 线段树区间更新更新一段区间,在更新区间的过程中,区间被分成几段,每一段的左右界限刚好是一个节点的tree[node].left和tree[node].right(如果不是继续分,直到是为止) ...
- hdu 1556 Color the ball(线段树区间维护+单点求值)
传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/3276 ...
- 2015 UESTC 数据结构专题A题 秋实大哥与小朋友 线段树 区间更新,单点查询,离散化
秋实大哥与小朋友 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 Desc ...
- hdu1556 Color the ball 线段树区间染色问题
都是老套路了,如果n=5,要把区间[1,4]染色,可以递归去染区间[1,3]和区间[4,4],如果区间相等就自加,不相等继续递归寻找对应区间. 打印结果时,把所有到达叶节点包含i的区间值相加,就是最后 ...
随机推荐
- 枚举类enum的values()方法
value()方法可以将枚举类转变为一个枚举类型的数组,因为枚举中没有下标,我们没有办法通过下标来快速找到需要的枚举类,这时候,转变为数组之后,我们就可以通过数组的下标,来找到我们需要的枚举类.接下来 ...
- C#窗体间传值的简便方法/工具
一.问题:窗体间传值必须需要窗体之间有联系,具体有如下方式 窗体间传值涉及到窗体A必须拥有窗体B,这样才可以实现A-B之间传值 窗体A与窗体B在窗体/实例C中,A-B可互相通讯 其他方式,不细讨论,复 ...
- mysql中 groupby分组
引用自http://www.cnblogs.com/mo-beifeng/archive/2012/02/07/2341886.html#2341105 --按某一字段分组取最大(小)值所在行的数据 ...
- python - list 列表推导式
一.如有两个list,分别为: a = [1,2,3,4,5,6]b = ["a","b","c","d"," ...
- 基于Spark Streaming预测股票走势的例子(二)
上一篇博客中,已经对股票预测的例子做了简单的讲解,下面对其中的几个关键的技术点再作一些总结. 1.updateStateByKey 由于在1.6版本中有一个替代函数,据说效率比较高,所以作者就顺便研究 ...
- 微信小程序之商品发布+编辑功能(多图片上传功能)
小程序的商品发布页面:功能有多图片上传 遇到的问题记录一下:1.uploadFile成功之后返回的参数是json字符串,一定要用JSON.parse转换为object格式 2.因为商品发布和编辑都是在 ...
- cocos creator学习
2019-05-30 22:23:27 按照前一节我发的教程做,大概了解了Cocos creator的基本布局 但是你发现你不好写代码(感觉视频没有提) 需要下载VS code软件,在其上进行编辑,教 ...
- python网络爬虫数据中的三种数据解析方式
一.正则解析 常用正则表达式回顾: 单字符: . : 除换行以外所有字符 [] :[aoe] [a-w] 匹配集合中任意一个字符 \d :数字 [0-9] \D : 非数字 \w :数字.字母.下划线 ...
- 加密解密Url字符串,C#对Url进行处理,传递Url
string _QueryStringKey = "abcdefgh"; //URL传输参数加密Key /// 加密URL传输的字符串 public string E ...
- MVC系列学习(六)-Razor语法
注:本次代码加了样式,样式如下 <style> div { border: 1px solid red; margin: 10px auto; ...

joey97
Mail 0
Control Panel
Sign Out