HDU1698 Just a Hook 线段树成段更新
来源:互联网 发布:手机淘宝开店怎么上架 编辑:程序博客网 时间:2024/05/22 04:40
基础的线段树成段更新,学习了notonlysuccess dalao的代码后写的
#include<iostream>#include<cstdio>#include<cstring>#include<ctime>#include<algorithm>#include<cstdlib>#include<cmath>#include<set>#include<bitset>#include<map>#include<stack>#include<queue>#include<vector>#include<utility>#define INF 0x3f3f3f3f#define inf 2*0x3f3f3f3f#define llinf 1000000000000000000#define pi acos(-1)#define mod 1000000007#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;typedef long long ll;typedef pair<int,int>P;int col[100005*4],sum[100005*4],t,n,q,x,y,z;void pushup(int rt){ sum[rt]=sum[rt<<1]+sum[rt<<1|1];}void pushdown(int rt,int m){ if (col[rt]) { col[rt<<1] = col[rt<<1|1] = col[rt]; sum[rt<<1] = (m - (m >> 1)) * col[rt]; sum[rt<<1|1] = (m >> 1) * col[rt]; col[rt] = 0; }}void build(int l,int r,int rt){ col[rt]=0; sum[rt]=1; if(l==r)return ; int m=(l+r)>>1; build(lson);build(rson); pushup(rt);}void change(int L,int R,int x,int l,int r,int rt){ if (L <= l && r <= R) { col[rt] = x; sum[rt] = x * (r - l + 1); return ; } pushdown(rt,r-l+1); int m=(l+r)>>1; if(L<=m)change(L,R,x,lson); if(R>m)change(L,R,x,rson); pushup(rt);}int main(){ cin>>t; for(int ca=1;ca<=t;ca++) { scanf("%d%d",&n,&q); build(1,n,1); while(q--) { scanf("%d%d%d",&x,&y,&z); change(x,y,z,1,n,1); } printf("Case %d: The total value of the hook is %d.\n",ca,sum[1]); } return 0;}
0 0
- HDU1698 Just a Hook 线段树成段更新
- HDU1698 Just a Hook 线段树成段更新
- Hdu1698 Just a Hook(线段树成段更新)
- 【线段树成段更新-模板】【HDU1698】Just a Hook
- hdu1698 Just a Hook(线段树成段更新lazy)
- hdu1698 Just a Hook 线段树成段替换
- HDU1698 Just a Hook(线段树成段替换)
- HDU1698 Just a Hook 线段树成段替换
- 线段树成断更新裸题hdu1698 Just a Hook
- HDU1698--Just a hook--线段树区间更新
- HDU1698:Just a Hook(线段树区间更新)
- hdu1698 Just a Hook 线段树,成段更新
- 线段树---成段更新hdu1698 Just a Hook
- hdu1698 Just a Hook(线段树区间更新)
- hdu1698 Just a Hook 线段树 延时更新
- hdu1698 Just a Hook (线段树区间更新 懒惰标记)
- HDU1698 - Just a Hook (线段树 区间更新)
- Just a Hook hdu1698 [线段树区间更新]
- 数据库
- SpringBoot之集成Spring AOP
- php与mysql程序设计第四版第六章:基本的oop(简易笔记)(完)
- c++函数对象构造函数和operator()执行关系
- Python函数之计算规则图形的面积
- HDU1698 Just a Hook 线段树成段更新
- 关于MVC、MVP架构
- MySQL数据库(入门)(二)
- 操作系统原理:动态内存分配
- java学习笔记(十四)冒泡与选择排序
- oc学习-4.12
- 【ZOJ3952 The 17th Zhejiang University Programming Contest E】【简单构造 模拟 or汇编】Fibonacci Sequence Chicken
- 听过讲座《如何敲开世界500强企业大门》的感想
- HDU1875通畅工程再续