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 ...
随机推荐
- South - 在 Django 中 Migrate Database
Web 开发避免不了经常修改表结构,手工修改表结构不仅容易出错,而且涉及到多人协作开发时,这么土的做法很不经济. Django 的第三方 app South 就是专门做数据库表结构自动迁移的.Jaco ...
- AX 2012 关于parts 添加
只有当引用parts的form中design属性style为 ListPage, DetailsFormMaster, or DetailsFormTransaction,才能创建FactBox pa ...
- Codeforces Round #228 (Div. 1) A
A. Fox and Box Accumulation time limit per test 1 second memory limit per test 256 megabytes input s ...
- STL之迭代器(iterator)
STL的中心思想在于:将数据容器和算法分开,彼此独立设计,最后再用一帖粘着剂将它们撮合在一起.没错,这个粘着剂正是迭代器(iterator).迭代器的主要目的是通过遍历来对容器中元素进行相关操作.算法 ...
- mvc中Scripts.Render、Styles.Render
一.配置BundleConfig.cs文件 1.首先要在App_Start 里面BundleConfig.cs 文件里面 添加要包含的css文件 2.BundleConfig就是一个微软新加的 一个打 ...
- 我要崩溃了,要解出这么一段js代码背后的东西,这真是一坨啊,别被高度欺骗了,他还有宽度!!!!!试着按下方向右键
一坨js代码: function s_gi(un, pg, ss) { var c = "s.version='H.26';s.an=s_an;s.logDebug=function(m){ ...
- 【EF学习笔记12】----------解释查询和本地查询 区分 Enumerable 和 Queryable
简单介绍:Enumerable 和 Queryable 他们都是静态类,位于命名控件 System.Linq下,分别为IEnumerable<T>和IQueryable<T>提 ...
- java8中hashMap
摘自:http://www.importnew.com/20386.html 简介 Java为数据结构中的映射定义了一个接口java.util.Map,此接口主要有四个常用的实现类,分别是HashMa ...
- RegExp 对象的三个方法:compile()、exec()、test()
这三个都是RegExp对象下的三个方法,使用方法是一致得. 使用方法:RegExpObject.方法() 方法解析:其实就是根据定义好的正则对象,调用对应的方法. 1.RegExpObject.com ...
- 转 系统级编程语言性能PK
http://www.solidot.org/story?sid=35754 看了此文,为什么我现在如此看好Rust C/C++已经统治系统编程很久,除了ObjectiveC之外语言都无法获得很高的关 ...