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 ;
}

最新文章

  1. [转]完美洗牌(Perfect Shuffle)问题
  2. C++之路进阶——HDU1880(魔咒词典)
  3. Yii2的深入学习--入口文件
  4. 股市非常态,CCI指标买卖点实例图解
  5. Cucumber
  6. 理解CSS3 transform中的Matrix(矩阵)
  7. 在github上写博客
  8. TCP/IP协议原理与应用笔记24:网际协议(IP)之 IP协议的简介
  9. 【Java基础之容器】Iterator
  10. AD认证
  11. java查找反复类/jar包/普通文件
  12. 深入理解计算机系统(2.7)------二进制小数和IEEE浮点标准
  13. Cocoa惯性思维调试一例
  14. Mybatis插入MySQL数据库中文乱码
  15. Java - String 的字面量、常量池、构造函数和intern()函数
  16. 阿里云 oss 图片上传解决方案 vue (web直传)
  17. spring-boot-2.0.3之quartz集成,数据源问题,源码探究
  18. JVM(3)对象A和B循环引用,最后会不会不被GC回收?-------关于Java的GC机制
  19. j.u.c系列(09)---之并发工具类:CyclicBarrier
  20. OpenGL ES3 非常好的系列文章

热门文章

  1. perl异常处理
  2. 【J-meter】正则表达式提取
  3. WHU 1548 Home 2-SAT
  4. Win 7中开启Telnet功能
  5. 国庆 day 6 上午
  6. impala jdbc4的group by语句的bug,加上limit没错
  7. HackingTeam重磅炸弹: 估值超1000万美金带有军火交易性质的木马病毒以及远控源代码泄露
  8. Introduction to IIS Architectures
  9. js易错点总结及 常见面试的坑
  10. Linux常用的安全工具