博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4107 Gangster
阅读量:5071 次
发布时间:2019-06-12

本文共 3364 字,大约阅读时间需要 11 分钟。

Gangster

Time Limit: 1000ms
Memory Limit: 32768KB
This problem will be judged on 
HDU. Original ID: 
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 11 2 12 3 1

Sample Output

1 3 1

Source

 
解题:线段树。。时间卡死人啊。。。多交几次g++就过了
 
1 #include 
2 #include
3 #include
4 #include
5 using namespace std; 6 const int maxn = 200010; 7 struct node { 8 int minv,maxv,lazy; 9 } tree[maxn<<2];10 int n,m,p;11 inline void pushdown(int v) {12 if(tree[v].lazy) {13 tree[v<<1].lazy += tree[v].lazy;14 tree[v<<1|1].lazy += tree[v].lazy;15 tree[v<<1].minv += tree[v].lazy;16 tree[v<<1|1].minv += tree[v].lazy;17 tree[v<<1].maxv += tree[v].lazy;18 tree[v<<1|1].maxv += tree[v].lazy;19 tree[v].lazy = 0;20 }21 }22 inline void pushup(int v) {23 tree[v].maxv = max(tree[v<<1].maxv,tree[v<<1|1].maxv);24 tree[v].minv = min(tree[v<<1].minv,tree[v<<1|1].minv);25 }26 void update(int L,int R,int lt,int rt,int val,int v) {27 if(lt <= L && rt >= R && (tree[v].minv >= p || tree[v].maxv < p)) {28 val <<= (tree[v].minv >= p);29 tree[v].minv += val;30 tree[v].maxv += val;31 tree[v].lazy += val;32 return;33 }34 pushdown(v);35 int mid = (L + R)>>1;36 if(lt <= mid) update(L,mid,lt,rt,val,v<<1);37 if(rt > mid) update(mid+1,R,lt,rt,val,v<<1|1);38 pushup(v);39 }40 void query(int L,int R,int v){41 if(L == R){42 if(L > 1) putchar(' ');43 printf("%d",tree[v].lazy);44 return;45 }46 pushdown(v);47 int mid = (L + R)>>1;48 query(L,mid,v<<1);49 query(mid+1,R,v<<1|1);50 }51 int main() {52 int a,b,c;53 while(~scanf("%d %d %d",&n,&m,&p)){54 memset(tree,0,sizeof tree);55 while(m--){56 scanf("%d %d %d",&a,&b,&c);57 update(1,n,a,b,c,1);58 }59 query(1,n,1);60 putchar('\n');61 }62 return 0;63 }
View Code

 

转载于:https://www.cnblogs.com/crackpotisback/p/4450167.html

你可能感兴趣的文章
leetcode 110 Balanced Binary Tree
查看>>
时间单位与存储单位换算
查看>>
OC调用Swift
查看>>
禅定感受记录 1
查看>>
node 开启本地服务器代码
查看>>
分分钟教会你使用HTML写Web页面
查看>>
ubuntu64运行32位程序安装过程
查看>>
HDU 2196 Computer
查看>>
我的学习
查看>>
Swift中的类和结构体的相同点与不同点
查看>>
XCode升级到7后,规范注释生成器VVDocumenter插件没有用了,怎么办?
查看>>
常见错误收集: lucene 读取word文档问题
查看>>
map基本用法
查看>>
爬虫系列1:Requests+Xpath 爬取豆瓣电影TOP
查看>>
String与StringBuffer的区别
查看>>
ASP方法进行301重定向实战演示
查看>>
Apache Beam 模型
查看>>
vue基础5-生命周期
查看>>
读取java目录中相同目录、相同名称的文件
查看>>
前端工作需要什么
查看>>