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. ejabberd服务端开发笔记

    网上一搜一大陀ejabberd安装配置的,扩展开发的资料少之又少,写个笔记记录一下. xmpp protocal: http://xmpp.org/xmpp-protocols/xmpp-extens ...

  2. 安卓处理原始XML文件

    // 获取XML文档(Parser:剖析器) XmlResourceParser parser = getResources().getXml(R.xml.person); try { // 文档未完 ...

  3. U盘分区之后如何恢复

    操作步骤: 1.插入U盘. 2.按windows键,右键点击“运行”,再左键点击以管理员身份运行. 3.输入diskpart,按enter. 4.输入list disk,按enter. 5.之后会看到 ...

  4. archlinux更新错误

    问题1 初始化下载: http://repo.archlinuxcn.org/x86_64/wps-office-10.1.0.5672_a21-2-x86_64.pkg.tar.xz 文件大小: 1 ...

  5. C语言基础_2

    scanf函数可以从键盘上读取数据并记录到变量中.为了使用这个函数也需要在文件开头使用如下的预处理指令#include <stdio.h>scanf函数使用的时候所需要的初始数据和prin ...

  6. CentOS使用virtualenv搭建独立的Python环境-python虚拟环境

    CentOS使用virtualenv搭建独立的Python环境-python虚拟环境 virtualenv可以搭建虚拟且独立的python环境,可以使每个项目环境与其他项目独立开来,保持环境的干净,解 ...

  7. jQuery.bind() 函数详解

    bind()函数用于为每个匹配元素的一个或多个事件绑定事件处理函数. 此外,你还可以额外传递给事件处理函数一些所需的数据. 执行bind()时,事件处理函数会绑定到每个匹配元素上.因此你使用bind( ...

  8. SVM2---核函数的引入

    前边总结了线性SVM,最终转化为一个QP问题来求解.后来又考虑到非线性SVM,如果特征特别特别多的话,直接使用QP的话求解不了,我们经过一系列的转化,把这一问题转化为训练集大小n量级的QP问题. ht ...

  9. Sql 查找整个数据库中的字符串

    --存储过程 CREATE PROCEDURE [dbo].[SP_FindValueInDB] ( @value VARCHAR() ) AS BEGIN SET NOCOUNT ON; DECLA ...

  10. how spring resolves a request

    quoted from answer at http://stackoverflow.com/questions/14015642/how-does-the-dispatcherservlet-res ...