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 集训难度【多标记线段树】的更多相关文章

  1. CSU OJ2151 集训难度

    小L正在组织acm暑假集训,但众所周知,暑假集训的萌新中有OI神犇,也有暑假才开始学算法的萌新,如果统一集训的难度,无法很好地让萌新们得到训练,所以小L想了一个办法,根据每次测试的情况,改变萌新们的集 ...

  2. HDU 5029 Relief grain 树链剖分打标记 线段树区间最大值

    Relief grain Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  3. POJ - 2777——Count Color(懒标记线段树二进制)

    Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 53639   Accepted: 16153 Des ...

  4. CSU - 1551 Longest Increasing Subsequence Again —— 线段树/树状数组 + 前缀和&后缀和

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1551 题意: 给出一段序列, 删除其中一段连续的子序列(或者不删), 使得剩下的序列 ...

  5. UOJ46 清华集训2014玄学(线段树)

    注意到操作有结合律,容易想到用一个矩形表示第i次操作对第j个位置的数的影响.那么修改是单行内的区间修改,而查询是单列内的区间查询.这样二维线段树上以列为外层行为内层直接打标记就可以维护.然后就喜闻乐见 ...

  6. LOJ.6062.[2017山东一轮集训]Pair(Hall定理 线段树)

    题目链接 首先Bi之间的大小关系没用,先对它排序,假设从小到大排 那么每个Ai所能匹配的Bi就是一个B[]的后缀 把一个B[]后缀的匹配看做一条边的覆盖,设Xi为Bi被覆盖的次数 容易想到 对于每个i ...

  7. 【2019北京集训2】duck 线段树优化建图+tarjan

    题目大意:给你$n$个点,第$i$个点有点权$v_i$.你需要将这$n$个点排成一排,第$i$个点的点权能被累加当且仅当这个点前面存在编号在$[l_i,r_i]$中的点,问你这些点应该如何排列,点权和 ...

  8. UOJ46. 【清华集训2014】玄学 [线段树,二进制分组]

    UOJ 思路 模拟赛出了这题,结果我没学过二进制分组--一波主席树然后空间就爆炸了-- 用线段树维护时间序列,每个节点维护\(a_i\to x_i\times a_i+b_i,i\in [1,n]\) ...

  9. Petrozavodsk Summer Training Camp 2016H(多标记线段树)题解

    题意: \(n\)个草,第\(0\)天种下,高度都为\(0\),每个草每天长高\(a_i\).现给出\(q\)询问,每次给出第\(b_i\)天,然后把高于\(d_i\)的全削成\(d_i\),每次问你 ...

随机推荐

  1. PowerDesigner16 活动图

    活动是某件事情正在进行的状态.活动在状态机中表现为一个由一系列动作组成 的非原子的执行过程. 活动图是一种描述系统行为的图,它用于展现 参与行为的实体所进行的各种活动的顺序关系.活动图(Activit ...

  2. 转【jenkins插件】

    开源版本的Jenkins 具有三大能力:Master-Slave的分布式构建调度能力.Pipeline编排能力.强大的开源生态(插件)能力. 2017年4月,Jenkins创始人KK(Kohsuke ...

  3. 【Foreign】K优解 [堆]

    K优解 Time Limit: 20 Sec  Memory Limit: 512 MB Description 给定n个行数,每行m个.在每行中选出一个数来,求出前 k 小的异或和. Input 第 ...

  4. 【51NOD】消灭兔子

    [算法]贪心 #include<cstdio> #include<algorithm> #include<cstring> #include<queue> ...

  5. JS中的实例方法与静态方法

    一.静态方法与实例方法的例子: 我们先来看一个例子来看一下JS中的静态方法和实例方法到底是什么 静态方法: function A(){} A.sayMeS=function(){ console.lo ...

  6. textarea输入框实时统计输入字符数

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. 8.0docker的客户端和守护进程

    C/S 链接的方式 unix:///var/run/docker.sock 默认的 tcp://host:port fd://socketfd 在linux上进行socket 模拟 nc -U /va ...

  8. linux系统环境 ——(四)

    默认有6个命令交互通道和一个图形界面交互通道,默认进入到的是图形界面通道 命令交互模式切换:ctrl+alt+f1---f6 图形交互界面 ctrl+alt+f7 1.图形界面交互模式 - termi ...

  9. python 学习笔记 sqlalchemy

    数据库表是一个二维表,包含多行多列.把一个表的内容用Python的数据结构表示出来的话,可以用一个list表示多行,list的每一个元素是tuple,表示一行记录,比如,包含id和name的user表 ...

  10. (十九)git版本管理软件——搭建git服务器

    创建管理员git 为管理员用户添加sudo权限 生成管理员秘钥 设置管理员git提交账号和邮箱 下载安装gitolite 启动gitolite 添加项目版本库 添加项目成员 项目成员下载项目 gito ...