HDU 1698 Just a Hook(线段树,成段更新)
2012-11-14 18:45
204 查看
链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1698
分析与总结:
我的第一道线段树成段更新题... 看刘汝佳大白书+傻崽的代码学习的
代码:
—— 生命的意义,在于赋予它意义士。
原创 http://blog.csdn.net/shuangde800 , By
D_Double (转载请标明)
http://acm.hdu.edu.cn/showproblem.php?pid=1698
分析与总结:
我的第一道线段树成段更新题... 看刘汝佳大白书+傻崽的代码学习的
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define mid ((left+right)>>1) #define lson rt<<1,left,mid #define rson rt<<1|1,mid+1,right #define int64 long long using namespace std; const int MAXN = 100005; int n,m; int sum[MAXN<<2],col[MAXN<<2]; inline void push_up(int rt){ sum[rt] = sum[rt<<1] + sum[rt<<1|1]; } inline void push_down(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 rt,int left,int right){ col[rt] = 0; sum[rt] = 1; if(left==right)return; build(lson); build(rson); push_up(rt); } void update(int rt,int left,int right,int l,int r,int data){ if(l<=left && right<=r) { col[rt] = data; sum[rt] = data*(right-left+1); return; } push_down(rt, right-left+1); int m = mid; if(l <= m) update(lson,l,r,data); if(r > m) update(rson,l,r,data); push_up(rt); } int main(){ int T,x,y,z,cas=1; scanf("%d", &T); while(T--){ scanf("%d%d",&n,&m); build(1,1,n); for(int i=0; i<m; ++i){ scanf("%d%d%d",&x,&y,&z); update(1,1,n,x,y,z); } printf("Case %d: The total value of the hook is %d.\n",cas++,sum[1]); } return 0; }
—— 生命的意义,在于赋予它意义士。
原创 http://blog.csdn.net/shuangde800 , By
D_Double (转载请标明)
相关文章推荐
- [ACM] hdu 1698 Just a Hook (线段树,成段更新,懒惰标记)
- HDU 1698 线段树成段更新模板
- hdu 1542线段树(成段更新+离散化)
- hdu 1698 线段树成段更新
- hdu 1698 线段树-成段更新
- 线段树(成段更新) HDU 1698 Just a Hook
- HDU-1698 Just a Hook 线段树成段更新
- HDU 3397 Sequence operation(线段树:成段更新,查询连续目标子串长度)
- hdu 4893(线段树 成段更新+区间合并)
- Hdu 1698 【线段树 成段更新】.cpp
- [ACM] hdu 1698 Just a Hook (线段树,成段更新,懒惰标记)
- hdu 1698 线段树 成段更新
- HDU 1698线段树成段更新
- 线段树 段更新 HDU 1698 Just a Hook (线段树区间修改)
- hdu 1698 Just a Hook 线段树 成段更新
- A Simple Problem with Integers----HDU_3468----线段树之成段更新
- hdu 1698 Just a Hook 线段树成段更新
- HDU 1698 Just a Hook / 线段树成段更新
- HDU4027——线段树成段更新——Can you answer these queries?
- hdu 4107 Gangster 线段树 成段更新 最后求每一位的值