hdu 4107 Gangster(区间更新)
来源:互联网 发布:单片机的加密模式 编辑:程序博客网 时间:2024/05/15 09:39
题意:长度为N的数组,进行m次操作,每次对于给定的区间,若这个区间的数比p大.则+c,否则+2*c;
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4107
思路:
和正常的那种lazy不相同,因为一个区间的数和p的大小不可以确定, 那么对于一个节点我们记录下最大值,最小值,以及延迟值,
若最大的值大于p.那么+c
若最小的值小于p,那么+2*c
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>using namespace std;#define maxn 200010#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1int n,m,p;int Max[maxn<<2];int Min[maxn<<2];int col[maxn<<2];int num[maxn];void PushUp(int rt){Max[rt] = max(Max[rt<<1],Max[rt<<1|1]);Min[rt] = min(Min[rt<<1],Min[rt<<1|1]);}void Pushdown(int rt){if(col[rt]){col[rt<<1] += col[rt];col[rt<<1|1] += col[rt];Max[rt<<1] += col[rt] ;Max[rt<<1|1] += col[rt] ;Min[rt<<1] += col[rt] ;Min[rt<<1|1] += col[rt] ;col[rt] = 0;}}void build(int l,int r,int rt){Max[rt] = 0;Min[rt] = 0;col[rt] = 0;if(l == r){num[l] = 0;return ;}int m = (l + r)/2;build(lson);build(rson);PushUp(rt);}void update(int L,int R,int c,int l,int r,int rt){if(L <= l && r <= R){if(Max[rt] < p){col[rt] += c;Max[rt] += c;Min[rt] += c;return ;}if(Min[rt] >= p){col[rt] += 2 * c;Max[rt] += 2 * c;Min[rt] += 2 * c;return ;}}int m = (l + r)/2;Pushdown(rt);if(L <= m) update(L,R,c,lson);if(m < R) update(L,R,c,rson);PushUp(rt);}void query(int l,int r,int rt){if(l == r){num[l] += col[rt];return ;}Pushdown(rt);int m = (l + r)/2;query(lson);query(rson);}int main(){int a,b,c;while(~scanf("%d %d %d",&n,&m,&p)){build(1,n,1);for(int i=0;i<m;i++){scanf("%d %d %d",&a,&b,&c);update(a,b,c,1,n,1);}query(1,n,1);printf("%d",num[1]);for(int i=2;i<=n;i++)printf(" %d",num[i]);printf("\n");}return 0;}
- hdu 4107 Gangster(区间更新)
- hdu 4107 Gangster
- HDU 4107 Gangster
- HDU 4107 Gangster
- HDU-4107-Gangster
- hdu 4107 Gangster 线段树 成段更新
- hdu 4107 Gangster 线段树
- hdu 4107 Gangster 线段数
- HDU 4107 Gangster (线段树)
- HDU 4107 Gangster Segment Tree线段树
- hdu 4107 Gangster(线段树)
- 线段树-hdu-Gangster
- HDOJ 4107 Gangster 线段树 成段更新变化
- hdu 4107 Gangster(线段树,时间卡得很严)
- hdu 4107 Gangster(线段树。时间卡的很紧)
- hdu 4107 Gangster (离线+打标记+树状数组)
- hdu 1698 区间更新
- hdu 4578(区间更新)
- 图片切换 MM_swapImg
- 数据结构c++实现----线性表
- 如何在Linux上部署网站
- Web Service单元测试工具实例介绍之SoapUI
- svn在linux下的使用(svn命令行)删除 新增 添加 提交 状态查询 恢...
- hdu 4107 Gangster(区间更新)
- java中序列化与反序列化对象的简单操作!
- JNI
- Java异常--其他概念—throw、throws、Exception、RuntimeException、断言
- 编写高质量代码-改善C++程序的150个建议-1
- WinCE 开机自启动应用软件
- 实用数据结构
- LwIP 协议栈源码详解 ——TCP/IP 协议的实现(六:网络接口结构)
- vc快速设置控件的tab顺序