Gangster

Time Limit: 1000ms
Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 4107
64-bit integer IO format: %I64d      Java class name: Main

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

 
解题:线段树。。时间卡死人啊。。。多交几次g++就过了
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = ;
struct node {
int minv,maxv,lazy;
} tree[maxn<<];
int n,m,p;
inline void pushdown(int v) {
if(tree[v].lazy) {
tree[v<<].lazy += tree[v].lazy;
tree[v<<|].lazy += tree[v].lazy;
tree[v<<].minv += tree[v].lazy;
tree[v<<|].minv += tree[v].lazy;
tree[v<<].maxv += tree[v].lazy;
tree[v<<|].maxv += tree[v].lazy;
tree[v].lazy = ;
}
}
inline void pushup(int v) {
tree[v].maxv = max(tree[v<<].maxv,tree[v<<|].maxv);
tree[v].minv = min(tree[v<<].minv,tree[v<<|].minv);
}
void update(int L,int R,int lt,int rt,int val,int v) {
if(lt <= L && rt >= R && (tree[v].minv >= p || tree[v].maxv < p)) {
val <<= (tree[v].minv >= p);
tree[v].minv += val;
tree[v].maxv += val;
tree[v].lazy += val;
return;
}
pushdown(v);
int mid = (L + R)>>;
if(lt <= mid) update(L,mid,lt,rt,val,v<<);
if(rt > mid) update(mid+,R,lt,rt,val,v<<|);
pushup(v);
}
void query(int L,int R,int v){
if(L == R){
if(L > ) putchar(' ');
printf("%d",tree[v].lazy);
return;
}
pushdown(v);
int mid = (L + R)>>;
query(L,mid,v<<);
query(mid+,R,v<<|);
}
int main() {
int a,b,c;
while(~scanf("%d %d %d",&n,&m,&p)){
memset(tree,,sizeof tree);
while(m--){
scanf("%d %d %d",&a,&b,&c);
update(,n,a,b,c,);
}
query(,n,);
putchar('\n');
}
return ;
}

HDU 4107 Gangster的更多相关文章

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

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

  2. HDU 4107 Gangster Segment Tree线段树

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

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

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

  4. hdu 4107

    Gangster Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  5. hdu 4107当卡段树

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

  6. HDU 4107 线段树

    给出N个节点,M次操作,和p 每次操作 对l-r区间的每一个节点+c,若节点值>=p,则加2*c: 结点存当前区间伤害最小值,最大值,以及lazy操作.更新到假设最小值大于等于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. 【Git 四】一款不错的 Git 客户端

    平常做开发使用 git bash 进行代码提交,一直没有使用过 git 相关的客户端. 直到有次同一分支下两个日志进行代码比较时,bash 返回的结果可视化理解起来比较差. 如果更改的部分比较多,问题 ...

  2. windows或linux安装python

    一.windows安装 先进入 python 官网:https://www.python.org/downloads/windows/ 选择合适的版本下载: 下载完成,双击运行安装[勾选Add to ...

  3. python BeautifulSoup 获取页面多个子节点中的各个节点的内容

    页面html格式为 <tr bgcolor="#7bb5de"><td style="border-bottom: 1px solid #C9D8AD& ...

  4. HDU 4889 Scary Path Finding Algorithm

    其实这个题是抄的题解啦…… 题解给了一个图,按照那个图模拟一遍大概就能理解了. 题意: 有一段程序,给你一个C值(程序中某常量),让你构造一组数据,使程序输出"doge" 那段代码 ...

  5. 一 SSH 无密码登陆 & Linux防火墙 & SELinux关闭

    如果系统环境崩溃.   调用/usr/bin/vim /etc/profile   SHH无密码登陆 所有要做得节点上运行   修改 host name vi /etc/sysconfig/netwo ...

  6. 最全面的AndroidStudio配置指南总结-包括护眼模式

    使用AndroidStudio开发APP已有半年多的时间了,从刚开始的不习惯到慢慢适应再到逐渐喜欢上AndroidStudio,中间的过程颇有一番曲折,现在把自己对AndroidStudio的配置心得 ...

  7. Android页面事件挂接模拟

    Java没有C#的引用类型.因此事件的挂接一般都是利用接口来实现,有两种方式: 1)定义一个实现事件接口的类,然后实现接口方法,然后通过将这个类的实例加入到事件监听器里面: public class ...

  8. 相比于HTML4,HTML5废弃的元素有哪些?

    第一类:表现性元素basefontbigcenterfontsstrikettu建议用语义正确的元素代替他们,并使用CSS来确保渲染后的效果 第二类:框架类元素因框架有很多可用性及可访问性问题,HTM ...

  9. CSS3侧滑导航

    <!DOCTYPE> <html> <head> <meta charset="utf-8" /> <meta name=&q ...

  10. ajax处理错误(六)

    使用ajax时必须留心两类错误,他们之间的区别源于视角不同. 一.第一类错误是从XMLHttpRequest对象的角度看到的问题:某些因素阻例如止了请求发送到服务器,例如DNS无法解析主机名,连接请求 ...