CSU 2151 集训难度【多标记线段树】
http://acm.csu.edu.cn/csuoj/problemset/problem?pid=2151
Input
第一行三个数n,m,v0 表示有n名萌新和m次调整,初始时全部萌新的集训难度都为v0
第2~m+1行 每行三个数或四个数
0 x y v 表示把 [x,y]区间内的萌新的集训难度都增加v
1 x y v 表示把 [x,y]区间内的萌新的集训难度都变为v
2 x y表示询问[x,y]区间内萌新的集训难度之和
0<n,m<=10^5, |v|<=10^5
Output
每个询问一行,输出答案
Sample Input
3 5 0
0 1 3 1
1 2 3 2
2 1 1
2 2 2
2 2 3
Sample Output
1
2
4
多标记线段树处理法(洛谷3373,codevs4927)
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define debug() puts("++++")
#define gcd(a,b) __gcd(a,b)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a,b,sizeof(a))
#define sz size()
#define be begin()
#define pu push_up
#define pd push_down
#define cl clear()
#define mdzz int mid=(l+r)>>1;
#define lowbit(x) -x&x
#define all 1,n,1
#define rep(i,x,n) for(int i=(x); i<(n); i++)
#define in freopen("in.in","r",stdin)
#define out freopen("out.out","w",stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const ll LNF = 1e18;
const int maxn = + ;
const int maxm = 1e6 + ;
const double PI = acos(-1.0);
const double eps = 1e-;
const int dx[] = {-,,,,,,-,-};
const int dy[] = {,,,-,,-,,-};
int dir[][] = {{,},{,-},{-,},{,}};
const int mon[] = {, , , , , , , , , , , , };
const int monn[] = {, , , , , , , , , , , , };
int n,m;
int x,y,op;
ll a[maxn];
ll sum[maxn<<],add[maxn<<],cover[maxn<<],z,v;
void pushup(int rt)
{
sum[rt]=sum[rt<<]+sum[rt<<|]; //区间查询和
}
void pushdown(int rt,int m)
{
if(cover[rt])
{
//区间覆盖
cover[rt<<] = cover[rt<<|] = cover[rt];
sum[rt<<] = cover[rt]*(m-(m>>));
sum[rt<<|] = cover[rt]*(m>>);
add[rt<<] = add[rt<<|] = ; //set操作中取消add
cover[rt] = ;
}
if(add[rt])
{
//区间求和
add[rt<<] += add[rt];
add[rt<<|] += add[rt];
sum[rt<<] += add[rt]*(m-(m>>));
sum[rt<<|] += add[rt]*(m>>);
add[rt]=;
}
}
void build(int l,int r,int rt)
{
add[rt]=cover[rt]=;
if(l==r)
{
sum[rt]=v;
return;
}
mdzz
build(lson);
build(rson);
pushup(rt);
}
void update(int op,int L,int R,int c,int l,int r,int rt)
{
if(L<=l && R>=r)
{
if(op==) //add
{
add[rt] += c;
sum[rt] += (ll)c*(r-l+);
}
else
{
cover[rt] = c;
add[rt] = ; //
sum[rt] = (ll)c*(r-l+);
}
return ;
}
pushdown(rt,r-l+);
mdzz
if(L<=mid) update(op,L,R,c,lson);
if(R>mid) update(op,L,R,c,rson);
pushup(rt);
}
ll query(int L,int R,int l,int r,int rt)
{
if(L<=l&&R>=r) return sum[rt];
pushdown(rt,r-l+);
mdzz
ll res=;
if(L<=mid) res += query(L,R,lson);
if(R>mid) res += query(L,R,rson);
return res;
} int main()
{
while(~scanf("%d%d%lld",&n,&m,&v))
{
build(,n,);
while(m--)
{
scanf("%d",&op);
if(op==)
{
scanf("%d%d",&x,&y);
printf("%lld\n",query(x,y,,n,));
}
else
{
scanf("%d%d%lld",&x,&y,&z);
update(op,x,y,z,,n,);
}
}
}
}
多次区间更新操作——>多个lazy
CSU 2151 集训难度【多标记线段树】的更多相关文章
- CSU OJ2151 集训难度
小L正在组织acm暑假集训,但众所周知,暑假集训的萌新中有OI神犇,也有暑假才开始学算法的萌新,如果统一集训的难度,无法很好地让萌新们得到训练,所以小L想了一个办法,根据每次测试的情况,改变萌新们的集 ...
- HDU 5029 Relief grain 树链剖分打标记 线段树区间最大值
Relief grain Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- POJ - 2777——Count Color(懒标记线段树二进制)
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 53639 Accepted: 16153 Des ...
- CSU - 1551 Longest Increasing Subsequence Again —— 线段树/树状数组 + 前缀和&后缀和
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1551 题意: 给出一段序列, 删除其中一段连续的子序列(或者不删), 使得剩下的序列 ...
- UOJ46 清华集训2014玄学(线段树)
注意到操作有结合律,容易想到用一个矩形表示第i次操作对第j个位置的数的影响.那么修改是单行内的区间修改,而查询是单列内的区间查询.这样二维线段树上以列为外层行为内层直接打标记就可以维护.然后就喜闻乐见 ...
- LOJ.6062.[2017山东一轮集训]Pair(Hall定理 线段树)
题目链接 首先Bi之间的大小关系没用,先对它排序,假设从小到大排 那么每个Ai所能匹配的Bi就是一个B[]的后缀 把一个B[]后缀的匹配看做一条边的覆盖,设Xi为Bi被覆盖的次数 容易想到 对于每个i ...
- 【2019北京集训2】duck 线段树优化建图+tarjan
题目大意:给你$n$个点,第$i$个点有点权$v_i$.你需要将这$n$个点排成一排,第$i$个点的点权能被累加当且仅当这个点前面存在编号在$[l_i,r_i]$中的点,问你这些点应该如何排列,点权和 ...
- UOJ46. 【清华集训2014】玄学 [线段树,二进制分组]
UOJ 思路 模拟赛出了这题,结果我没学过二进制分组--一波主席树然后空间就爆炸了-- 用线段树维护时间序列,每个节点维护\(a_i\to x_i\times a_i+b_i,i\in [1,n]\) ...
- Petrozavodsk Summer Training Camp 2016H(多标记线段树)题解
题意: \(n\)个草,第\(0\)天种下,高度都为\(0\),每个草每天长高\(a_i\).现给出\(q\)询问,每次给出第\(b_i\)天,然后把高于\(d_i\)的全削成\(d_i\),每次问你 ...
随机推荐
- 【设计模式】 模式PK:命令模式VS策略模式
1.概述 命令模式和策略模式的类图确实很相似,只是命令模式多了一个接收者(Receiver)角色.它们虽然同为行为类模式,但是两者的区别还是很明显的.策略模式的意图是封装算法,它认为“算法”已经是一个 ...
- 汕头市队赛SRM 20 T1魔法弹
T1 背景 “主角光环已经不能忍啦!” 被最强控制AP博丽灵梦虐了很长一段时间之后,众人决定联合反抗. 魂魄妖梦:“野怪好像被抢光了?” 十六夜咲夜:“没事,我们人多.” 然后当然是以失败告终了. 八 ...
- 【BZOJ】1666 [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
[算法]贪心&&堆 [题解]反过来看就是合并任意两块木板,花费为木板长度之和. 显然从最小的两块开始合并即可,用堆(优先队列)维护. 经典DP问题石子归并是只能合并相邻两堆石子,所以不 ...
- 崩坏3mmd中的渲染技术研究
http://youxiputao.com/articles/11839 主要是参考该篇文章做一个微小的复盘. 漫反射与高光 文章中的漫反射与高光并不是类似于普通的 resultCol = Diffu ...
- word-wrap word-break 区别
word-wrap word-break 区别 word-break * word-break:break-all;//直接把单词截断 * word-break:break-word;//虽然单词截断 ...
- 工具_HBuilder使用快捷方式
HBuilder常用快捷键大概共9类([4 13 3]文件.编辑.插入:[4 9 8]选择.跳转.查找:[1 1 6]运行.工具.视图) 1.文件(4) 新建 Ctrl + N 关闭 Ctrl + F ...
- Eclipse svn 忽略文件夹/ svn 设置不同步
Eclipse 开发中我们经常用到SVN插件, 但是对于某些文件的缓存来说, 我们只要有操作缓存便会保存一次, 每次提交很是麻烦, 小编这里教你一种不同步某个文件夹的方法 工具/原料 MyEclips ...
- 【DeepLearning学习笔记】Coursera课程《Neural Networks and Deep Learning》——Week2 Neural Networks Basics课堂笔记
Coursera课程<Neural Networks and Deep Learning> deeplearning.ai Week2 Neural Networks Basics 2.1 ...
- [Leetcode Week16]Insertion Sort List
Insertion Sort List 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/insertion-sort-list/description/ ...
- KVM虚拟机建立快照
部分转载: http://blog.csdn.net/gg296231363/article/details/6899533 windows虚拟机默认镜像格式为raw,快照默认格式为qcow2.win ...