Gangster

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3123    Accepted Submission(s): 762

Problem Description
There
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.
 
Input
The input consists several testcases.
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).
 
Output
Print A[1] to A[n] in one line. All the numbers are separated by a space.
 
Sample Input
3 2 1
1 2 1
2 3 1
 
Sample Output
1 3 1
 
Source
 
Recommend
lcy   |   We have carefully selected several similar problems for you:  4104 4102 4103 4105 4106
题意不想说 ,妈的 什么破题目 ,一样的代码第一次交就过,第二次就wa
时间卡,这段时间杭电也卡,我快晕了
线段树,用c++交
 #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的更多相关文章

  1. HDU 4107 Gangster

    Gangster Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 4 ...

  2. HDU 4107 Gangster(线段树 特殊懒惰标记)

    两种做法. 第一种:标记区间最大值和最小值,若区间最小值>=P,则本区间+2c,若区间最大值<P,则本区间+c.非常简单的区间更新. 最后发一点牢骚:最后query查一遍就行,我这个2B竟 ...

  3. HDU 4107 Gangster Segment Tree线段树

    这道题也有点新意,就是须要记录最小值段和最大值段,然后成段更新这个段,而不用没点去更新,达到提快速度的目的. 本题过的人非常少,由于大部分都超时了,我严格依照线段树的方法去写.一開始竟然也超时. 然后 ...

  4. hdu 4107当卡段树

    其核心思想是记录最大的节点值和最低值,假设max<p要么min>=p时间,在节点只变化add值,不要子树遍历:否则,就往子树递归. #include<iostream> #in ...

  5. HDU 4107 线段树

    给出N个节点,M次操作,和p 每次操作 对l-r区间的每一个节点+c,若节点值>=p,则加2*c: 结点存当前区间伤害最小值,最大值,以及lazy操作.更新到假设最小值大于等于P,或者最大值小于 ...

  6. hdu 4107 Gangster(线段树,时间卡得很严)

    这道题目的数据卡得好厉害. 题目明显是考察线段树延迟标记的,但是因为要考虑到p的值,这种延迟是有条件的:在该节点下所有的数据对于p都应该位于p的同一侧.要么都比p大,要么都比p小. 开始的时候我用一个 ...

  7. hdu4107Gangster 线段树

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/4107/ 题目给定一个初始值都是零的序列,操作只有一种,就是给一个区间加上一个数,但是当一个数大于等于给定的P的时 ...

  8. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  9. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

随机推荐

  1. 实用的VS工具

    工具 1.Visual Studio Visual Studio Productivity Power tool:Visual Studio专业版(及以上)的扩展,具有丰富的功能,如快速查找,导航解决 ...

  2. CRM 2016 subgrid 的显示隐藏

    function OnLoad() { //这里隐藏添加子记录的(+) 号按钮 hide_add_btn(); //这里隐藏鼠标在子记录上时的(删除)按钮 hide_del_btn(); //这里处理 ...

  3. JAVA设计模式之责任链模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述责任链(Chain of Responsibility)模式的: 责任链模式是一种对象的行为模式.在责任链模式里,很多对象由每一个对象对其 ...

  4. dijkstra

    寻找从源结点到其他点之间的最短距离. 把给出的结点分成两组,一组a刚开始为空,另一组b为全部节点,dis[i]记录从源点到i结点的距离,同样当所有操作结束后dis[i]就是到达源点的最短距离啦,每次更 ...

  5. assembly打包。

    --排除 <?xml version="1.0" encoding="UTF-8"?><assembly    xmlns="htt ...

  6. 如何用js刷新aspxgridviw

    //写在js中 ASPxGridView1.Refresh();

  7. Linux下find命令

    转自:http://www.cnblogs.com/skynet/archive/2010/12/25/1916873.html 1.1.find命令的一般形式 man文档中给出的find命令的一般形 ...

  8. SQL笔记-第六章,索引与约束

    一.索引 CREATE INDEX 索引名 ON 表名(字段1, 字段2,……字段n) CREATE INDEX idx_person_nameage ON T_Person(FName,FAge) ...

  9. Mybatis 插入null值报错

    解决方法: 1.在settings中配置 <setting name="jdbcTypeForNull" value="OTHER"/> MyBat ...

  10. sqlite支持各种交集差集 并集操作了