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. 「 Luogu P1850 」 换教室

    解题思路 很明显的是个期望 $dp$. 先前想到 $dp[i][j]$ 表示第决策到第 $i$ 个时间段,已经进行了 $j$ 次申请,然后就没有然后了,因为这根本就没法转移啊,你又不知道前 $i-1$ ...

  2. Luogu P1297 [国家集训队]单选错位

    P1297 [国家集训队]单选错位 题目背景 原 <网线切割>请前往P1577 题目描述 gx和lc去参加noip初赛,其中有一种题型叫单项选择题,顾名思义,只有一个选项是正确答案.试卷上 ...

  3. <SpringMvc>入门三 参数绑定

    1.get请求 <%--请求参数的绑定--%> <%--get请求参数--%> <a href="/param/testParam1?username=tom& ...

  4. MyBatis 中传递多个参数的 4 种方式

    方式 1 :封装成对象入参  #{对应实体类的属性} //UserMapper.java 接口 /** * 多条件查询:根据用户名称(模糊查询)和用户角色查询用户列表(参数:对象入参) * @para ...

  5. 解决windows安装TensorFlow2.0beta版本时ERROR: Cannot uninstall 'wrapt'问题

    pip install -U --ignore-installed wrapt enum34 simplejson netaddr 参考:https://bugs.launchpad.net/rall ...

  6. oldboy python 3.5 week 1

    #!/usr/bin/env python # -*- coding:utf-8 -*- ------------------------------------------- name = inpu ...

  7. IBOutlet loadView UIButton的subview数量 UIWebView

    IBOutlet声明的插座变量和属性一起使用的时候,在.m文件调用的是属性. 在loadView方法中获取view属性会产生循环引用问题并导致内存溢出. Control+E到行尾,Control+A到 ...

  8. HUD——1286 找新朋友

    思路: 裸的欧拉函数 代码: #include<cstdio> #include<cstring> #include<cstdlib> #include<io ...

  9. MongoDB:最简单的增删改查(Oops,可能太简单了)

    热身运动: 1. 启动MongoDB shell => mongo.exe or ./mongo(先确保有一个mongod的实例): 2. 切换到一个用于练手的namespace => u ...

  10. C++ new malloc realloc

    int* a = new int;          分配了存储空间,但没有赋初值 int* a = new int(10)     分配了存储空间,并赋初值,即*a = 10 int* a = ne ...