hdu1698 Just a Hook 线段树成段替换
来源:互联网 发布:万花尺软件 编辑:程序博客网 时间:2024/06/05 05:35
题目:点击打开链接
题意:给你T组数据,N个数(初始时每个数的值为1),M个操作,每个操作把区间[a,b]里的数更新为c,问最后这N个数的和是多少
分析:
因为只是最后查询总区间的和,所以只需要更新就可以了
#include<cstdio>#include<algorithm>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn=111111;int h,w,n;int col[maxn<<2];int sum[maxn<<2];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; if(l==r){ sum[rt]=1; return; } int m=(l+r)>>1; 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){ col[rt]=c; sum[rt]=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); PushUP(rt);}int main(){ int T,n,m; scanf("%d",&T); for(int cas=1;cas<=T;cas++){ scanf("%d%d",&n,&m); build(1,n,1); while(m--){ int a,b,c; scanf("%d%d%d",&a,&b,&c); update(a,b,c,1,n,1); } printf("Case %d: The total value of the hook is %d.\n",cas,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 线段树成段更新
- Hdu1698 Just a Hook(线段树成段更新)
- 【线段树成段更新-模板】【HDU1698】Just a Hook
- hdu1698 Just a Hook(线段树成段更新lazy)
- 【线段树】 hdu1698 Just a Hook
- Just a Hook(hdu1698,线段树)
- hdu1698 Just a Hook(线段树)
- 线段树之HDU1698 Just a Hook
- hdu1698 Just a Hook(线段树)
- Just a Hook HDU1698 线段树
- hdu1698 Just a Hook 线段树
- HDU1698[JUST A HOOK] 线段树
- 线段树 hdu1698 Just a Hook
- HDU1698:Just a Hook(线段树)
- 最长单调递增子序列
- java java中subString、split、stringTokenizer三种截取字符串方法的性能比较
- EditText相关
- 解决Tomcat服务器访问链接数过大的问题
- SpringMVC 连接Redis数据库
- hdu1698 Just a Hook 线段树成段替换
- hihocoder14(2)赛车
- STL入门要点
- 使用 C++ 处理 JSON 数据交换格式
- iOS7 CookBook精彩瞬间(二)NSSet、通过Subscript访问类成员等
- 动态分配内存之new
- 人丑就要多读书(14)
- NoClassDefFoundError: org/springframework/expression/PropertyAccessor
- java.lang.IllegalArgumentException: MALFORMED jar解析中文报错问题