http://codevs.cn/problem/4927/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string> using namespace std;
const int N = 1e5 + ; #define oo 1423333339
#define LL long long
#define gg 465432477 struct Node {
LL l, r, w, f, mx, mi, fg;
bool qs;
} T[N << ];
LL n, m, answer, maxn, minn; inline LL read() {
LL x = , f = ;
char c = getchar();
while(c < '' || c > '') { if(c == '-')f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
} void imp(LL jd) {
T[jd].w = T[jd << ].w + T[jd << | ].w;
T[jd].mx = max(T[jd << ].mx, T[jd << | ].mx);
T[jd].mi = min(T[jd << ].mi, T[jd << | ].mi);
} void down(LL jd) {
if(T[jd].qs) {
T[jd << ].f = ;
T[jd << ].qs = ;
T[jd << ].fg = T[jd].fg;
T[jd << ].w = (T[jd << ].r - T[jd << ].l + ) * T[jd].fg; T[jd << | ].f = ;
T[jd << | ].qs = ;
T[jd << | ].fg = T[jd].fg;
T[jd << | ].w = (T[jd << | ].r - T[jd << | ].l + ) * T[jd].fg; T[jd << ].mi = T[jd << ].mx = T[jd << | ].mi= T[jd << | ].mx=T[jd].fg; T[jd].fg = ;
T[jd].qs = ;
}
if(T[jd].f) {
T[jd << ].f += T[jd].f;
T[jd << ].w += (T[jd << ].r - T[jd << ].l + ) * T[jd].f;
T[jd << ].mi += T[jd].f;
T[jd << ].mx += T[jd].f; T[jd << | ].f += T[jd].f;
T[jd << | ].w += (T[jd << | ].r - T[jd << | ].l + ) * T[jd].f;
T[jd << | ].mi += T[jd].f;
T[jd << | ].mx += T[jd].f; T[jd].f = ;
}
return ;
} void build_tree(LL l, LL r, LL jd) {
T[jd].l = l;
T[jd].r = r;
if(l == r) {
T[jd].w = read();
T[jd].mx = T[jd].w;
T[jd].mi = T[jd].w;
return ;
}
LL mid = (l + r) >> ;
build_tree(l, mid, jd << );
build_tree(mid + , r, jd << | );
imp(jd);
} void Sec_g(LL l, LL r, LL jd, LL x, LL y, LL yj) {
if(x <= l && r <= y) {
T[jd].f += yj;
T[jd].w += (T[jd].r - T[jd].l + ) * yj;
T[jd].mi += yj;
T[jd].mx += yj;
return ;
}
if(T[jd].f || T[jd].qs)
down(jd);
LL mid = (l + r) >> ;
if(x <= mid)
Sec_g(l, mid, jd << , x, y, yj);
if(y > mid)
Sec_g(mid + , r, jd << | , x, y, yj);
imp(jd);
} void Sec_set(LL l, LL r, LL jd, LL x, LL y, LL k) {
if(x <= l && r <= y) {
T[jd].fg = k;
T[jd].qs = ;
T[jd].w = (T[jd].r - T[jd].l + ) * T[jd].fg;
T[jd].mx = k;
T[jd].mi = k;
T[jd].f = ;
return ;
}
LL mid = (l + r ) >> ;
if(T[jd].f || T[jd].qs)
down(jd);
if(x <= mid)
Sec_set(l, mid, jd << , x, y, k);
if(y > mid)
Sec_set(mid + , r, jd << | , x, y, k);
imp(jd);
} void Sec_calc(LL l, LL r, LL jd, LL x, LL y) {
if(x <= l && r <= y) {
answer += T[jd].w;
return;
}
if(T[jd].f || T[jd].qs)
down(jd);
LL mid = (l + r) >> ;
if(x <= mid)
Sec_calc(l, mid, jd << , x, y);
if(y > mid)
Sec_calc(mid + , r, jd << | , x, y);
} void Sec_min(LL l, LL r, LL jd, LL x, LL y) {
if(x <= l && r <= y) {
minn = min(minn, T[jd].mi);
return ;
}
if(T[jd].f || T[jd].qs)
down(jd);
LL mid = (l + r) >> ;
if(x <= mid)
Sec_min(l, mid, jd << , x, y);
if(y > mid)
Sec_min(mid + , r, jd << | , x, y);
} void Sec_max(LL l, LL r, LL jd, LL x, LL y) {
if(x <= l && r <= y) {
maxn = max(maxn, T[jd].mx);
return ;
}
if(T[jd].f || T[jd].qs)
down(jd);
LL mid = (l + r) >> ;
if(x <= mid)
Sec_max(l, mid, jd << , x, y);
if(y > mid)
Sec_max(mid + , r, jd << | , x, y);
} int main() {
freopen("gg.in", "r", stdin);
n = read();
m = read();
build_tree(, n, );
for(LL i = ; i <= m; i ++) {
string s;
cin >> s;
LL x = read();
LL y = read();
if(s == "add") {
LL k = read();
Sec_g(, n, , x, y, k);
continue;
}
if(s == "set") {
LL k = read();
Sec_set(, n, , x, y, k);
continue;
}
if(s == "sum") {
answer = ;
Sec_calc(, n, , x, y);
printf("%lld\n", answer);
continue;
}
if(s == "min") {
minn = oo;
Sec_min(, n, , x, y);
printf("%lld\n", minn);
continue;
}
if(s == "max") {
maxn = -oo;
Sec_max(, n, , x, y);
printf("%lld\n", maxn);
continue;
}
}
return ;
}
/*
10 6
3 9 2 8 1 7 5 0 4 6
add 4 9 4
set 2 6 2
sum 2 10
max 1 7
min 3 6
*/

[codevs]线段树练习5的更多相关文章

  1. codevs 线段树练习ⅠⅡⅢ

    1080 线段树练习  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 一行N个方格,开始每个格子里都有 ...

  2. codevs 1082 线段树练习 3(区间维护)

    codevs 1082 线段树练习 3  时间限制: 3 s  空间限制: 128000 KB  题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...

  3. codevs 1576 最长上升子序列的线段树优化

    题目:codevs 1576 最长严格上升子序列 链接:http://codevs.cn/problem/1576/ 优化的地方是 1到i-1 中最大的 f[j]值,并且A[j]<A[i] .根 ...

  4. codevs 1080 线段树点修改

    先来介绍一下线段树. 线段树是一个把线段,或者说一个区间储存在二叉树中.如图所示的就是一棵线段树,它维护一个区间的和. 蓝色数字的是线段树的节点在数组中的位置,它表示的区间已经在图上标出,它的值就是这 ...

  5. codevs 1082 线段树区间求和

    codevs 1082 线段树练习3 链接:http://codevs.cn/problem/1082/ sumv是维护求和的线段树,addv是标记这歌节点所在区间还需要加上的值. 我的线段树写法在运 ...

  6. codevs 1080 线段树练习

    链接:http://codevs.cn/problem/1080/ 先用树状数组水一发,再用线段树水一发 树状数组代码:84ms #include<cstdio> #include< ...

  7. 线段树练习 codevs 1080

    /* codevs 1080 线段树练习 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 一行N个方格,开 ...

  8. codevs 1080 线段树练习 CDQ分治

    codevs 1080 线段树练习 http://codevs.cn/problem/1080/  时间限制: 1 s  空间限制: 128000 KB   题目描述 Description 一行N个 ...

  9. 4163 hzwer与逆序对 (codevs + 权值线段树 + 求逆序对)

    题目链接:http://codevs.cn/problem/4163/ 题目:

随机推荐

  1. Spring Boot使用@ConfigurationProperties注解获取配置文件中的属性值

    注意:这种方式要提供属性的getter/setter方法—— 如果idea报错,提示没有相应的执行器,就需要在maven中添加: (虽然不配置代码也能正常运行,作用在下面会说明) 配置了该执行器后,在 ...

  2. idea下spring boot jpa写原生sql的时候,报Cannot resolve table错误

    错误如图 打开View→Tool Windows→Persistence选项 在弹出的Persistence窗口的项目上右键,选择Generate Persistence Mapping→By Dat ...

  3. flutter从入门到精通四

    widget Flutter 从 React 中吸取灵感(如果有react的编程经验,会很容易理解flutter),通过现代化框架创建出精美的组件. 它的核心思想是用 widget 来构建你的 UI ...

  4. uni-app 入门之 nvue (weex) 爬坑记

    前言 uni-app 是 DCloud 出品的新一代跨端框架,可以说是目前跨端数最多的框架之一了,目前支持发布到:App(Android/iOS).H5.小程序(微信小程序/支付宝小程序/百度小程序/ ...

  5. 正则表达式字符&使用

    正则详细解说:https://juejin.im/post/5965943ff265da6c30653879 一.正则表达式中的字符含意 \ 做为转义,即通常在"\"后面的字符不按 ...

  6. ScrollView小记

    常用代理方法: - (void)scrollViewDidScroll:(UIScrollView *)scrollView 只有  [self.scrolView setContentOffset: ...

  7. 如何把SAP Kyma和SAP Cloud for Customer连接起来

    首先进入SAP Cloud for Customer的Administration的工作中心,打开General Settings视图,进入Event Notification配置UI: 新建一个C4 ...

  8. HTML5 使用localstorage 本地存储

    HTML 本地存储介绍 最早的 Cookies 自然是大家都知道,问题主要就是太小,大概也就 4KB 的样子,而且 IE6 只支持每个域名20个cookies,太少了.优势就是大家都支持,而且支持得还 ...

  9. Android笔记(十二)AndroidManiFest.xml

    AndroidManiFest.xml清单文件是每个Android项目所必须的,它是整个Android应用的全局描述文件.AndroidManiFest.xml清单文件说明了该应用的名称.所使用的图标 ...

  10. unittest 运行slenium(三)---通过数据驱动形式运行用例

    一: 获取数据 获取用例所在位置,通过OpenExcelPandas来读取用例里面的全部数据.通过某个列名来创建新的序号. 并将结果转换成list类型,将其作为ddt数据的来源. 1.  在test文 ...