poj3468线段树标记永久化
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; ll value[N<<],lazy[N<<];
void build(int l,int r,int rt)
{
lazy[rt]=;
if(l==r)
{
scanf("%lld",&value[rt]);
return ;
}
int m=(l+r)>>;
build(ls);
build(rs);
value[rt]=value[rt<<]+value[rt<<|];
}
void update(int L,int R,ll c,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
lazy[rt]+=c;
//value[rt]+=c*(r-l+1);
return ;
}
int m=(l+r)>>;
if(L<=m)update(L,R,c,ls);
if(m<R)update(L,R,c,rs);
value[rt]=value[rt<<]+value[rt<<|]+lazy[rt<<]*(m-l+)+lazy[rt<<|]*(r-m);
}
ll query(int L,int R,ll add,int l,int r,int rt)
{
if(L<=l&&r<=R)
return (add+lazy[rt])*(r-l+)+value[rt];
int m=(l+r)>>;
ll ans=;
if(L<=m)ans+=query(L,R,add+lazy[rt],ls);
if(m<R)ans+=query(L,R,add+lazy[rt],rs);
return ans;
}
char s[];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
build(,n,);
while(m--)
{
scanf("%s",s);
if(s[]=='Q')
{
int l,r;
scanf("%d%d",&l,&r);
printf("%lld\n",query(l,r,,,n,));
}
else
{
int l,r;ll c;
scanf("%d%d%lld",&l,&r,&c);
update(l,r,c,,n,);
//printf("%d\n",query(1,n,0,1,n,1));
}
}
}
return ;
}
/********************
5
10000
1 1 1 1 1
w 1 3 2
w 2 4 3
w 1 5 1
********************/
标记永久化
poj3468线段树标记永久化的更多相关文章
- BZOJ4785 [Zjoi2017]树状数组 【二维线段树 + 标记永久化】
题目链接 BZOJ4785 题解 肝了一个下午QAQ没写过二维线段树还是很难受 首先题目中的树状数组实际维护的是后缀和,这一点凭分析或经验或手模观察可以得出 在\(\mod 2\)意义下,我们实际求出 ...
- Codeforces 258E - Little Elephant and Tree(根号暴力/线段树+标记永久化/主席树+标记永久化/普通线段树/可撤销线段树,hot tea)
Codeforces 题目传送门 & 洛谷题目传送门 yyq:"hot tea 不常有,做过了就不能再错过了" 似乎这是半年前某场 hb 模拟赛的 T2?当时 ycx.ym ...
- P3332 [ZJOI2013]K大数查询(线段树套线段树+标记永久化)
P3332 [ZJOI2013]K大数查询 权值线段树套区间线段树 把插入的值离散化一下开个线段树 蓝后每个节点开个线段树,维护一下每个数出现的区间和次数 为了防止MLE动态开点就好辣 重点是标记永久 ...
- 洛谷P3437 [POI2006]TET-Tetris 3D(二维线段树 标记永久化)
题意 题目链接 Sol 二维线段树空间复杂度是多少啊qwqqq 为啥这题全网空间都是\(n^2\)还有人硬要说是\(nlog^2n\)呀.. 对于这题来说,因为有修改操作,我们需要在外层线段树上也打标 ...
- bzoj 1513 POI2006 Tet-Tetris 3D 二维线段树+标记永久化
1511: [POI2006]OKR-Periods of Words Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 351 Solved: 220[S ...
- HFUUOJ1024 动态开点线段树+标记永久化
题意 分析 动态加点线段树,标记永久化好写常数小 Code #include<bits/stdc++.h> #define fi first #define se second #defi ...
- 洛谷 P3688 - [ZJOI2017]树状数组(二维线段树+标记永久化)
题面传送门 首先学过树状数组的应该都知道,将树状数组方向写反等价于前缀和 \(\to\) 后缀和,因此题目中伪代码的区间求和实质上是 \(sum[l-1...n]-sum[r...n]=sum[l-1 ...
- 【BZOJ3110】K大数查询(权值线段树套线段树+标记永久化,整体二分)
题意:有N个位置,M个操作.操作有两种,每次操作 如果是1 a b c的形式表示在第a个位置到第b个位置,每个位置加入一个数c 如果是2 a b c形式,表示询问从第a个位置到第b个位置,第C大的数是 ...
- hdu 4578 线段树(标记处理)
Transformation Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 65535/65536 K (Java/Others) ...
随机推荐
- python中counter()记数
一:定义一个list数组,求数组中每个元素出现的次数 如果用Java来实现,是一个比较复杂的,需要遍历数组list. 但是Python很简单:看代码 a = [1,4,2,3,2,3,4,2] fro ...
- 3.Write Scripts for the mongo Shell-官方文档摘录
总结 1 使用js进行获取数据的方法 2 js方式和原生mongo shell的交互方式的区别写法 3 需要将所有数据打印出来使用到的循环示例 cursor = db.collection.find( ...
- git 从远程仓库指定分支clone代码到本地
不指定分支 git clone + clone 地址 # 例如 git clone https://amc-msra.visualstudio.com/xxx/_xx/xxxxxx 指定分支 git ...
- 通过文件对照工具Merge数据库
项目分成线下开发版.线上測试版.线上生产版,因此相应有三个数据库. 对于一些静态数据.经常须要同步.改动了线下的开发版本号,同一时候也须要更新线上的測试版和线上生产版数据库,有时候线上的一些数据库改动 ...
- ZOJ 2770 Burn the Linked Camp 差分约束
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemCode=2770 Burn the Linked Camp Time Limi ...
- 利用VMware克隆 windows 虚拟机需要注意的事项
利用VMware克隆windows虚拟机需要注意的事项--克隆虚拟机 --powershell 在域服务器使用,查看所有的sid dsquery computer|dsget computer -dn ...
- beego——ORM使用方法
先来看一个简单示例: models.gp package main import ( "github.com/astaxie/beego/orm" ) type User stru ...
- loc、iloc、ix比较
使用pandas创建一个对象 In [1]: import pandas as pd In [2]: import numpy as np In [3]: df = pd.DataFrame(np.r ...
- Python函数之初体验
定义函数 在Python中,定义一个函数要使用def语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块中编写函数体,函数的返回值用return语句返回. 我们先定义一个求字符串长度的函数 ...
- 解决hash冲突的办法
1.开发定址法 2.再哈希法 3.链地址法 4.建立一个公共溢出区