hdu 1698 Just a Hook 线段树成段更新
来源:互联网 发布:ubuntu怎么配置ip 编辑:程序博客网 时间:2024/06/05 14:10
裸的成段更新。。。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;#define maxn 110000#define lson rt<<1,l,m#define rson rt<<1|1,m+1,rint tree[maxn<<2],lazy[maxn<<2];void pushup(int rt){ tree[rt]=tree[rt<<1]+tree[rt<<1|1];}void pushdown(int rt,int mid){ if(lazy[rt]) { lazy[rt<<1]=lazy[rt<<1|1]=lazy[rt]; tree[rt<<1]=lazy[rt]*(mid-(mid>>1)); tree[rt<<1|1]=lazy[rt]*(mid>>1); lazy[rt]=0; }}void build(int rt,int l,int r){ int m=(l+r)>>1; lazy[rt]=0; if(l==r) { tree[rt]=1; return; } build(lson); build(rson); pushup(rt);}void update(int rt,int l,int r,int x,int y,int val){ if(x<=l&&r<=y) { lazy[rt]=val; tree[rt]=val*(r-l+1); return; } pushdown(rt,r-l+1); int m=(l+r)>>1; if(x<=m) { update(lson,x,y,val); } if(y>m) { update(rson,x,y,val); } pushup(rt);}int query(int rt,int l,int r,int x,int y){ if(x==l&&y==r) { return tree[rt]; } pushdown(rt,r-l+1); int m=(l+r)>>1; int tmp=0; if(y<=m) { return query(lson,x,y); } else if(x>m) { return query(rson,x,y); } else { return query(lson,x,m)+query(rson,m+1,y); }}int main(){ int cas=0,n,m,t; int a,b,c; scanf("%d",&t); while(t--) { scanf("%d",&n); build(1,1,n); scanf("%d",&m); for(int i=1;i<=m;i++) { scanf("%d%d%d",&a,&b,&c); update(1,1,n,a,b,c); } int ans=query(1,1,n,1,n); cas++; printf("Case %d: The total value of the hook is %d.\n",cas,ans); } return 0;}
0 0
- 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,线段树成段更新
- 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(线段树成段更新)
- 线段树成段更新 hdu 1698 Just a Hook
- hdu 1698 Just a Hook(线段树成段更新lazy)
- HDU 1698 Just a Hook 线段树成段更新
- HDU-1698Just a Hook-线段树成段更新
- hdu Just a Hook 线段树成段更新.cpp
- HDU 1698 Just a Hook [线段树-成段更新]
- HDU 1698 Just a Hook 线段树区间更新
- hdu 1698 Just a Hook(线段树 成段更新)
- How Btree Indexes Are Maintained (Doc ID 30405.1)
- Intent 传递Object对象类型数据
- 股票,最大收益
- hdu 3081 hdu 3277 hdu 3416 Marriage Match II III IV //最大流的灵活运用
- Linux进程的状态转换图
- hdu 1698 Just a Hook 线段树成段更新
- 【tarjan模板】HDU 1269 迷宫城堡
- HDU 2181 哈密顿绕行世界问题 (dfs)
- 员工部门表综合查询SQL
- ARM平台Linux内核空指针异常处理流程
- 项目分配问题
- java 获取文件名(不包括文件的后缀)和文件重命名
- UVA - 10534Wavio Sequence(LIS)
- usb serial驱动流程分析