for (i=; i<; i++)
tree[i][]=tree[i][]=i;
for (i=; i>=; i--)
tree[i][]=tree[i+i][],
tree[i][]=tree[i+i+][];
void Down(int x)
{
tree[x+x][]+=tree[x][];
tree[x+x+][]+=tree[x][];
tree[x+x][]+=tree[x][]*
(tree[x+x][]-tree[x+x][]+);
tree[x+x+][]+=tree[x][]*
(tree[x+x+][]-tree[x+x+][]+);
tree[x][]=;
}
int work(int root,int l,int r,int k)
{
if (tree[root][]==l &&
tree[root][]==r)
{
tree[root][]+=k;
tree[root][]+=k*(r-l+);
return ;
}
tree[root][]+=k*(r-l+);
//Down(root);
int mid=(tree[root][]+tree[root][])/;
if (l<=mid)
work(root+root,l,min(mid,r),k);
if (r>mid)
work(root+root+,max(mid+,l),r,k);
// tree[root][3]=tree[root+root][3]+tree[root+root+1][3];
return;
}
int work2(int root,int l,int r)
{
if (tree[root][]==l &&
tree[root][]==r)
return tree[root][];
Down(root);
int mid=(tree[root][]+tree[root][])/;
int p=,q=;
if (l<=mid)
p=work2(root+root,l,min(mid,r));
if (r>mid)
q=work2(root+root+,max(mid+,l),r);
return p+q;
} while (Q--)
{
cin>>A;
if (A==)
{
cin>>x>>y>>z;
work(,x+,y+,z);
}
if (A==)
{
cin>>x>>y;
cout<<work2(,x+,y+);
}
}
tree[i][] 表示编号最小的叶子
tree[i][] 编号最大的叶子
tree[i][] 以i为根,所有叶子一次性全部加的,
总共加了多少。
tree[i][] 以i为根,所有叶子的权值之和是多少

zhw大神线段树姿势的更多相关文章

  1. 【BZOJ-4530】大融合 线段树合并

    4530: [Bjoi2014]大融合 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 280  Solved: 167[Submit][Status] ...

  2. [LOJ#2980][THUSCH2017]大魔法师(线段树+矩阵)

    每个线段树维护一个行向量[A,B,C,len]分别是这个区间的A,B,C区间和与区间长度,转移显然. 以及此题卡常,稍微哪里写丑了就能100->45. #include<cstdio> ...

  3. LOJ 2980 「THUSCH 2017」大魔法师——线段树

    题目:https://loj.ac/problem/2980 线段树维护矩阵. 然后是 30 分.似乎是被卡常了?…… #include<cstdio> #include<cstri ...

  4. [BZOI2014]大融合——————线段树进阶

    竟然改了不到一小时就改出来了, 可喜可贺 Description Solution 一开始想的是边两侧简单路径之和的乘积,之后发现这是个树形结构,简单路径数就是节点数. 之后的难点就变成了如何求线段树 ...

  5. 北大zhw大神bzoj1756代码

    #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #i ...

  6. HDU 5091---Beam Cannon(线段树+扫描线)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...

  7. BZOJ-1699 Balanced Lineup 线段树区间最大差值

    Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 41548 Accepted: 19514 Cas ...

  8. HDU1199 动态线段树 // 离散化

    附动态线段树AC代码 http://acm.hdu.edu.cn/showproblem.php?pid=1199 因为昨天做了一道动态线段树的缘故,今天遇到了这题没有限制范围的题就自然而然想到了动态 ...

  9. [CodeChef - STREETTA] The Street 李超线段树

    大致题意: 给出两个序列A,B,A初始为负无穷,B初始为0,有三种操作 1.在A上区间[u,v]上加一个等差数列,取与原本A序列的最大值. 2.在B上区间[u,v]上加一个等差数列. 3.给出一个点X ...

随机推荐

  1. poj3061 Subsequence【尺取法】

    Description A sequence of N positive integers (10 < N < 100 000), each of them less than or eq ...

  2. buf.writeUInt8()函数详解

    buf.writeUInt8(value, offset[, noAssert]) value {Number} 需要被写入到 Buffer 的字节 offset {Number} 0 <= o ...

  3. on绑定事件支持的事件类型

    blurfocusfocusinfocusoutloadresizescrollunloadclickdblclickmousedownmouseupmousemovemouseovermouseou ...

  4. rsync+sersync自动同步备份数据

    一.为什么要用Rsync+sersync架构?1.sersync是基于Inotify开发的,类似于Inotify-tools的工具2.sersync可以记录下被监听目录中发生变化的(包括增加.删除.修 ...

  5. LINUX驱动、系统底层

    就业模拟测试题-LINUX驱动.系统底层工程师职位 本试卷从考试酷examcoo网站导出,文件格式为mht,请用WORD/WPS打开,并另存为doc/docx格式后再使用 试卷编号:143921试卷录 ...

  6. Leetcode 93.复制IP地址

    复制IP地址 给定一个只包含数字的字符串,复原它并返回所有可能的 IP 地址格式. 示例: 输入: "25525511135" 输出: ["255.255.11.135& ...

  7. POJ 3270 置换群问题

    题目大意是: 每头牛都有一个对应的值a[i],现在给定一个初始的牛的序列,希望通过两两交换,能够使这些牛按值升序排列,每次交换都会耗费一个 a[i]+a[j] 希望耗费最小,求出这个最小耗费 个人觉得 ...

  8. codeforces 371D

    #include<stdio.h> #define N 210000 struct node { int x,next; __int64 count,vec; }pre[N]; int n ...

  9. 终于又弄完一个DJANGO BY EXAMPLE的测试

    感觉学到了很多东东,都是以前开发不曾用到的. 知识的作用是到用时,知道到哪里去查相关的功能..:) 这个bookmarks就有很多功能点值得学习呢...

  10. Just a Hook 线段树 区间更新

    Just a Hook In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of t ...