kuangbin——线段树专题 E - Just a Hook
来源:互联网 发布:mac西柚色口红专柜价格 编辑:程序博客网 时间:2024/06/13 09:23
/*************************************************************************> File Name: C.cpp> Author:chudongfang > Mail:1149669942@qq.com > Created Time: 2016年08月04日 星期四 08时17分23秒 ************************************************************************/#include <iostream>#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <algorithm>#define INF 0x3f3f3f3fusing namespace std;typedef long long ll;#define M 111111#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1ll sum[M<<2];ll add[M<<2];void pushplus(int rt){ sum[rt] = sum[rt<<1] + sum [rt<<1|1];}void pushdown(int rt,int m){ if(add[rt]){ add[rt<<1] = add[rt]; add[rt<<1|1] = add[rt]; sum[rt<<1] = add[rt] * (m - (m >> 1)); sum[rt<<1|1] = add[rt] * (m >> 1); add[rt] = 0; }}void build(int l,int r,int rt){ if(l == r){ sum[rt] = 1; add[rt] = 0; return; } int m = (l+r)>>1; build(lson); build(rson); pushplus(rt); }void update(int L,int R,int c,int l,int r ,int rt){ if(L <= l && r<=R) { add[rt] = c; sum[rt] = (ll)c * (r-l+1); return ; } pushdown(rt , r-l+1); int m = (l+r)>>1; if(L<=m) update(L,R,c,lson); if(R>m) update(L,R,c,rson); pushplus(rt);}int main(int argc,char *argv[]){ int q,a,b,c,n,T; scanf("%d",&T); for(int k=1;k<=T;k++) { memset(sum,0,sizeof(sum)); memset(add,0,sizeof(add)); scanf("%d %d",&n,&q); build(1,n,1); for(int i=1;i<=q;i++) { scanf("%d %d %d",&a,&b,&c); update(a,b,c,1,n,1); } printf("Case %d: The total value of the hook is %lld.\n", k,sum[1]); } return 0;}
0 0
- kuangbin——线段树专题 E - Just a Hook
- nbut线段树专题E - Just a Hook
- 线段树专题—HDU1698 Just a Hook
- kuangbin——线段树专题 A - 敌兵布阵
- HDU 1698 Just a Hook【线段树—区间更新】
- Just a Hook(线段树)
- 线段树 Just a Hook
- 线段树 Just a hook
- [kuangbin带你飞]专题七 线段树 【A、B、C、E、G、H】
- HDU 1698 Just a Hook 线段树
- [hdu]1698 Just a Hook -- 线段树
- hdu 1698 Just a Hook 线段树
- HDU 1698 JUST A HOOK(线段树)
- HDU 1698 Just a Hook 线段树
- 【线段树】 hdu1698 Just a Hook
- hdu Just a Hook (线段树)
- hdoj 1698 Just a Hook 【线段树】
- Just a Hook+线段树更新
- kuangbin——线段树专题 C - A Simple Problem with Integers
- 基础函数
- hdu 2089 不要62(数位DP/暴力)
- JStry&catch
- C语言:用异或^实现数据加密
- kuangbin——线段树专题 E - Just a Hook
- SkipList跳表的实现
- 弹幕效果实现
- HDU 5793 A Boring Question(快速幂+求逆元)
- OJ3311数据结构实验之串三:KMP应用
- 面试中关于key/value的问题及map的理解
- leetcode_c++: Regular Expression Matching(010)
- 从Windows到Linux(二)
- js函数