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. javaSwing文本域文件

    public class JTextAreaTest extends JFrame{    public JTextAreaTest()    {            setSize(200, 40 ...

  2. python socket 常见方法及 简单服务/客户端

    socket 常见方法: 补充说明:what is file descriptor? 文件描述符是什么? 参考(http://stackoverflow.com/questions/8191905/w ...

  3. Mono addin 学习笔记 5 TypeExtensionPoint

    1. Attribute声明方式 定义扩展点: [TypeExtensionPoint]public interface ICommand{        void Run();} 定义扩展: [Ex ...

  4. pytion学习1

    个人感觉学习一门新语言,简单的语法懂一点足矣.接下来就是编程.读懂别人程序的每一句,理解每一句的意义. #Filename:MyAddressBook.py import cPickle as p i ...

  5. 浅谈js的键值对key和value

    > 昨晚无意中看到类似下面结构的一段代码的取值问题,引起我的兴趣,花了点时间写了个demo给大家分享一下... var obj = [ {"2011":{"name ...

  6. [转载]: delphi中XLSReadWrite控件的使用(1)---简介

    XLSReadWrite控件简介: 一个你需要的,能在Delphi和.NET下访问Excel文件的完美解决方案. 一个经典的读写Excel的控件,对于使用Excel 开发很有帮助 官方网站: http ...

  7. 借助取色工具ColorPix对Pycharm编辑器设定自己喜欢的代码颜色_20161202

    1.Pycharm编辑器怎么设定自己喜欢的颜色,前几天看爬虫博客,看博主贴出的代码颜色很是喜欢,如下图,设置了好多次找不到他设定的颜色. 2.下班回家想起来之前做表的时候用到过一个取色工具ColorP ...

  8. phpunit.xml

    <phpunit bootstrap="vendor/autoload.php"> <testsuites> <testsuite name=&quo ...

  9. 学习笔记008之Task

    栈 为后进先出 如何实现一个弹出窗体.

  10. jquery :checked(过滤选择器) 和 空格:checked(后代选择器)

    jquery 过滤选择器 和 后代选择器 <%@ page language="java" contentType="text/html; charset=UTF- ...