hdu 4107
Gangster
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3123 Accepted Submission(s): 762
are two groups of gangsters fighting with each other. The first group
stands in a line, but the other group has a magic gun that can shoot a
range [a, b], and everyone in that range will take a damage of c points.
When a gangster is taking damage, if he has already taken at least P
point of damage, then the damage will be doubled. You are required to
calculate the damage that each gangster in the first group toke.
To
simplify the problem, you are given an array A of length N and a magic
number P. Initially, all the elements in this array are 0.
Now, you
have to perform a sequence of operation. Each operation is represented
as (a, b, c), which means: For each A[i] (a <= i <= b), if A[i]
< P, then A[i] will be A[i] + c, else A[i] will be A[i] + c * 2.
Compute all the elements in this array when all the operations finish.
The
first line contains three integers n, m, P (1 <= n, m, P <=
200000), denoting the size of the array, the number of operations and
the magic number.
Next m lines represent the operations. Each
operation consists of three integers a; b and c (1 <= a <= b <=
n, 1 <= c <= 20).
1 2 1
2 3 1
#include<iostream>
#include<cstdio>
using namespace std;
#define N 200004
int n,m,p;
struct node
{
int left,right;
int max,min;
int num;
}tree[N*];
void build(int l,int r,int pos)
{
int mid=(l+r)>>;
tree[pos].left=l;
tree[pos].right=r;
tree[pos].max=;
tree[pos].min=;
tree[pos].num=;
if(l==r)
{
return ;
}
build(l,mid,pos<<);
build(mid+,r,pos<<|);
}
void update(int l,int r,int pos,int v)
{
int mid=(tree[pos].left+tree[pos].right)>>;
if(tree[pos].left==l&&tree[pos].right==r)
{
if(tree[pos].min>=p)
{
tree[pos].min+=v<<;
tree[pos].max+=v<<;
tree[pos].num+=v<<;
return ;
}
if(tree[pos].max<p)
{
tree[pos].min+=v;
tree[pos].max+=v;
tree[pos].num+=v;
return ;
}
}
if(tree[pos].num!=)
{
tree[pos<<].num+=tree[pos].num;
tree[pos<<].min+=tree[pos].num;
tree[pos<<].max+=tree[pos].num;
tree[pos<<|].num+=tree[pos].num;
tree[pos<<|].min+=tree[pos].num;
tree[pos<<|].max+=tree[pos].num;
tree[pos].num=;
}
if(r<=mid)
update(l,r,pos<<,v);
else if(l>mid)
update(l,r,pos<<|,v);
else
{
update(l,mid,pos<<,v);
update(mid+,r,pos<<|,v);
}
if(tree[pos*].max>tree[pos<<|].max)
tree[pos].max=tree[pos<<].max;
else
tree[pos].max=tree[pos<<|].max;
if(tree[pos*].min>tree[pos<<|].min)
tree[pos].min=tree[pos<<|].min;
else
tree[pos].min=tree[pos<<].min;
}
void query(int pos)
{
if(tree[pos].left==tree[pos].right)
{
if(tree[pos].left!=)
printf(" ");
printf("%d",tree[pos].num);
return;
}
if(tree[pos].num!=)
{
tree[pos<<].num+=tree[pos].num;
tree[pos<<|].num+=tree[pos].num;
tree[pos].num=;
}
query(pos<<);
query(pos<<|);
}
int main()
{
while(scanf("%d%d%d",&n,&m,&p)>)
{
build(,n,);
while(m--)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
update(a,b,,c);
}
query();
printf("\n");
}
return ;
}
hdu 4107的更多相关文章
- HDU 4107 Gangster
Gangster Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 4 ...
- HDU 4107 Gangster(线段树 特殊懒惰标记)
两种做法. 第一种:标记区间最大值和最小值,若区间最小值>=P,则本区间+2c,若区间最大值<P,则本区间+c.非常简单的区间更新. 最后发一点牢骚:最后query查一遍就行,我这个2B竟 ...
- HDU 4107 Gangster Segment Tree线段树
这道题也有点新意,就是须要记录最小值段和最大值段,然后成段更新这个段,而不用没点去更新,达到提快速度的目的. 本题过的人非常少,由于大部分都超时了,我严格依照线段树的方法去写.一開始竟然也超时. 然后 ...
- hdu 4107当卡段树
其核心思想是记录最大的节点值和最低值,假设max<p要么min>=p时间,在节点只变化add值,不要子树遍历:否则,就往子树递归. #include<iostream> #in ...
- HDU 4107 线段树
给出N个节点,M次操作,和p 每次操作 对l-r区间的每一个节点+c,若节点值>=p,则加2*c: 结点存当前区间伤害最小值,最大值,以及lazy操作.更新到假设最小值大于等于P,或者最大值小于 ...
- hdu 4107 Gangster(线段树,时间卡得很严)
这道题目的数据卡得好厉害. 题目明显是考察线段树延迟标记的,但是因为要考虑到p的值,这种延迟是有条件的:在该节点下所有的数据对于p都应该位于p的同一侧.要么都比p大,要么都比p小. 开始的时候我用一个 ...
- hdu4107Gangster 线段树
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/4107/ 题目给定一个初始值都是零的序列,操作只有一种,就是给一个区间加上一个数,但是当一个数大于等于给定的P的时 ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- ctags+cscope
a opensource study website http://www.lanedo.com/2013/the-hidden-pearls-of-tracker-2/ http://www.lan ...
- 使用gson解析,生成Json
包:gson-2.3.jarJson文本解析为Java对象:Java对象生成为Json文本 import com.google.gson.Gson; public class TestGson { c ...
- SimpleDateFormat做成员或者静态成员多线程安全隐患
转自:http://blog.csdn.net/jeamking/article/details/7183958 有时我们在同一个类中都是使用同一种日期格式,又或者为了减少new SimpleDate ...
- C++中调用Python脚本
C++中调用Python脚本的意义就不讲了,至少你可以把它当成文本形式的动态链接库, 需要的时候还可以改一改,只要不改变接口, C++的程序一旦编译好了,再改就没那么方便了 先看Python的代码 代 ...
- SQL递归
递归一般出现在树形结构中 1:根据孩子节点查找所有父节点 With T As ( Select * From U_Companies TB Where CompanyID=80047 Union Al ...
- 初学javaweb,远离各自框架
OSCHINA 软件库有一个分类--Web框架,该分类中包含多种编程语言的将近500个项目. Web框架是开发者在使用某种语言编写Web应用服务端时关于架构的最佳实践.很多Web框架是从实际的Web项 ...
- css的一种预处理器 sass
之前觉得关于css什么的没什么,后来让别人给问住了...然后就悲催了... sass是一种css的预处理器,是一种函数式的css的编程: 主要还是看官网 http://www.w3cplus.com/ ...
- (转)javascript中的对象查找
本文转自:http://otakustay.com/object-lookup-in-javascript/ ---很棒的一篇文章,作者的其他文章还暂时没读,但相信作者是一个谦虚 谨慎的好工程师 近 ...
- ---Under Ubuntu 14.04
Thinprint provides driver-free printing. Do you wish to enable this feature? [yes] Disabling timer-b ...
- thinkphp加载 和url_model
1.加载thinkphp.php requrie('./ThinkPHP/ThinkPHP.php'); 2.加载核心文件 ./thinkPHP/LIB/core 3.加载项目的文件 分析URL 调用 ...