HDU 4107 Gangster
Gangster
This problem will be judged on HDU. Original ID: 4107
64-bit integer IO format: %I64d Java class name: Main
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 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
Sample Input
3 2 1
1 2 1
2 3 1
Sample Output
1 3 1
Source
#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的更多相关文章
- HDU 4107 Gangster(线段树 特殊懒惰标记)
两种做法. 第一种:标记区间最大值和最小值,若区间最小值>=P,则本区间+2c,若区间最大值<P,则本区间+c.非常简单的区间更新. 最后发一点牢骚:最后query查一遍就行,我这个2B竟 ...
- HDU 4107 Gangster Segment Tree线段树
这道题也有点新意,就是须要记录最小值段和最大值段,然后成段更新这个段,而不用没点去更新,达到提快速度的目的. 本题过的人非常少,由于大部分都超时了,我严格依照线段树的方法去写.一開始竟然也超时. 然后 ...
- hdu 4107 Gangster(线段树,时间卡得很严)
这道题目的数据卡得好厉害. 题目明显是考察线段树延迟标记的,但是因为要考虑到p的值,这种延迟是有条件的:在该节点下所有的数据对于p都应该位于p的同一侧.要么都比p大,要么都比p小. 开始的时候我用一个 ...
- hdu 4107
Gangster Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu 4107当卡段树
其核心思想是记录最大的节点值和最低值,假设max<p要么min>=p时间,在节点只变化add值,不要子树遍历:否则,就往子树递归. #include<iostream> #in ...
- HDU 4107 线段树
给出N个节点,M次操作,和p 每次操作 对l-r区间的每一个节点+c,若节点值>=p,则加2*c: 结点存当前区间伤害最小值,最大值,以及lazy操作.更新到假设最小值大于等于P,或者最大值小于 ...
- hdu4107Gangster 线段树
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/4107/ 题目给定一个初始值都是零的序列,操作只有一种,就是给一个区间加上一个数,但是当一个数大于等于给定的P的时 ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- ln---创建链接
ln命令用来为文件创件连接,连接类型分为硬连接和符号连接两种,默认的连接类型是硬连接.如果要创建符号连接必须使用"-s"选项. 注意:符号链接文件不是一个独立的文件,它的许多属性依 ...
- Python学习笔记(3)--数据结构之列表list
Python的数据结构有三种:列表.元组和字典 列表(list) 定义:list是处理一组有序项目的数据结构,是可变的数据结构. 初始化:[], [1, 3, 7], ['a', 'c'], [1, ...
- Trie树的常见应用大总结(面试+附代码实现)
(一)Trie的简单介绍 Trie树,又称字典树,单词查找树或者前缀树.是一种用于高速检索的多叉树结构,如英文字母的字典树是一个26叉树.数字的字典树是一个10叉树. 他的核心思想是空间换时间,空间消 ...
- BZOJ2016: [Usaco2010 Feb]Chocolate Eating
[传送门:BZOJ2016] 简要题意: 贝西收到了N 块巧克力,她会在接下来的D 天里吃掉这些巧克力,她想制定一个计划,让她每 天的快乐度都保持在较高的水品上. 在第一天刚开始的时候,贝西的快乐度为 ...
- ISheet ICell
/// <summary> /// Gets the first row on the sheet /// </summary> /// <value>the nu ...
- thinkphp里面的or查询
thinkphp里面的or查询 whereOr 方法 使用whereOr 方法进行OR 查询: Db::table('think_user') ->where('name','like','%t ...
- string类自定义字符串替换函数replace
#include <iostream> #include <string> using namespace std; /* * 函数功能:将string字符串中的某些字符替换 ...
- jquery.base64.js
(function($) { $.base64 = function(options) { var defaults = { data:"", type:0, unicode:tr ...
- java httpRequest和Response
Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象.request和response对象即然代表请求和响应,那我们要 ...
- 学习TF:《TensorFlow实战》中文版PDF+源代码
深度学习乃至人工智能正逐渐在FinTech领域发挥巨大的作用,其应用包括自动报告生成.金融智能搜索.量化交易和智能投顾.而TensorFlow为金融业方便地使用深度学习提供了可能.<Tensor ...