题意

题目链接

单点修改,区间mod,区间和

Sol

如果x > mod ,那么 x % mod < x / 2

证明:

即得易见平凡,

仿照上例显然,

留作习题答案略,

读者自证不难。

反之亦然同理,

推论自然成立,

略去过程Q.E.D.,

由上可知证毕。

然后维护个最大值就做完了。。

复杂度不知道是一个log还是两个log,大概是两个吧(线段树一个+最多改log次。)

#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long
#define LL long long
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
using namespace std;
const int MAXN = 1e6 + 10, mod = 1e9 + 7, INF = 1e9 + 10;
const double eps = 1e-9;
template <typename A, typename B> inline bool chmin(A &a, B b){if(a > b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmax(A &a, B b){if(a < b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline LL add(A x, B y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;}
template <typename A, typename B> inline void add2(A &x, B y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);}
template <typename A, typename B> inline LL mul(A x, B y) {return 1ll * x * y % mod;}
template <typename A, typename B> inline void mul2(A &x, B y) {x = (1ll * x * y % mod + mod) % mod;}
template <typename A> inline void debug(A a){cout << a << '\n';}
template <typename A> inline LL sqr(A x){return 1ll * x * x;}
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, M, a[MAXN];
#define ls k << 1
#define rs k << 1 | 1
LL sum[MAXN];
int mx[MAXN];
void update(int k) {
sum[k] = sum[ls] + sum[rs];
mx[k] = max(mx[ls], mx[rs]);
}
void Build(int k, int ll, int rr) {
if(ll == rr) {sum[k] = mx[k] = read(); return ;}
int mid = ll + rr >> 1;
Build(ls, ll, mid); Build(rs, mid + 1, rr);
update(k);
}
LL Query(int k, int l, int r, int ql, int qr) {
if(ql <= l && r <= qr) return sum[k];
int mid = l + r >> 1;
if(ql > mid) return Query(rs, mid + 1, r, ql, qr);
else if(qr <= mid) return Query(ls, l, mid, ql, qr);
else return Query(ls, l, mid, ql, qr) + Query(rs, mid + 1, r, ql, qr);
}
void Modify(int k, int l, int r, int p, int v) {
if(l == r) {sum[k] = mx[k] = v; return ;}
int mid = l + r >> 1;
if(p <= mid) Modify(ls, l, mid, p, v);
else Modify(rs, mid + 1, r, p, v);
update(k);
}
void Mod(int k, int l, int r, int ql, int qr, int x) {
if(mx[k] < x) return ;
if(l == r) {sum[k] = mx[k] % x; mx[k] %= x; return ;}
int mid = l + r >> 1;
if(ql <= mid) Mod(ls, l, mid, ql, qr, x);
if(qr > mid) Mod(rs, mid + 1, r, ql, qr, x);
update(k);
}
signed main() {
N = read(); M = read();
Build(1, 1, N);
while(M--) {
int opt = read();
if(opt == 1) {
int l = read(), r = read();
cout << Query(1, 1, N, l, r) << '\n';
} else if(opt == 2) {
int l = read(), r = read(), x = read();
Mod(1, 1, N, l, r, x);
} else {
int k = read(), x = read();
Modify(1, 1, N, k, x);
}
}
return 0;
}
/* */

cf250D. The Child and Sequence(线段树 均摊复杂度)的更多相关文章

  1. HDU - 5306 Gorgeous Sequence 线段树 + 均摊分析

    Code: #include<algorithm> #include<cstdio> #include<cstring> #define ll long long ...

  2. 【loj6029】「雅礼集训 2017 Day1」市场 线段树+均摊分析

    题目描述 给出一个长度为 $n$ 的序列,支持 $m$ 次操作,操作有四种:区间加.区间下取整除.区间求最小值.区间求和. $n\le 100000$ ,每次加的数在 $[-10^4,10^4]$ 之 ...

  3. 【uoj#228】基础数据结构练习题 线段树+均摊分析

    题目描述 给出一个长度为 $n$ 的序列,支持 $m$ 次操作,操作有三种:区间加.区间开根.区间求和. $n,m,a_i\le 100000$ . 题解 线段树+均摊分析 对于原来的两个数 $a$ ...

  4. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸

    D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  5. Codeforces 438D The Child and Sequence - 线段树

    At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at ...

  6. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间求和+点修改+区间取模

    D. The Child and Sequence   At the children's day, the child came to Picks's house, and messed his h ...

  7. CF(438D) The Child and Sequence(线段树)

    题意:对数列有三种操作: Print operation l, r. Picks should write down the value of . Modulo operation l, r, x. ...

  8. CodeForces 438D The Child and Sequence (线段树 暴力)

    传送门 题目大意: 给你一个序列,要求在序列上维护三个操作: 1)区间求和 2)区间取模 3)单点修改 这里的操作二很讨厌,取模必须模到叶子节点上,否则跑出来肯定是错的.没有操作二就是线段树水题了. ...

  9. bzoj4127 Abs 树链剖分+线段树+均摊分析

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4127 题解 首先区间绝对值和可以转化为 \(2\) 倍的区间正数和 \(-\) 区间和.于是问 ...

随机推荐

  1. Linux巩固记录(2) java项目的编译和执行

    由于要近期使用hadoop等进行相关任务执行,操作linux时候就多了 以前只在linux上配置J2EE项目执行环境,无非配置下jdk,部署tomcat,再通过docker或者jenkins自动部署上 ...

  2. Win10 安装 digits

    安装caffe配置python接口 接下来就按照官方教程来安装了... 1. If the installation process complains compiler not found, you ...

  3. vue教程3-03 vue组件,定义全局、局部组件,配合模板,动态组件

    vue教程3-03 vue组件,定义全局.局部组件,配合模板,动态组件 一.定义一个组件 定义一个组件: 1. 全局组件 var Aaa=Vue.extend({ template:'<h3&g ...

  4. Django设置联合唯一约束 -- migrate时报错处理

    异常信息: a unique database constraint for 2 or more fields together 场景描述: 对于ORM中多对多关系的中间表,如果该关系表是手动创建的, ...

  5. Nuget 打包

    https://github.com/NuGetPackageExplorer/NuGetPackageExplorer 下载地址 1 打包的dll 中没有依赖 最简单的情况,保证dll放到lib下, ...

  6. 剑指offer七之斐波那契数列

    一.题目 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项.n<=39. 二.思路 序号:                  0  1   2   3  4   5  ...

  7. CentOS 部署 Python3 的一些注意事项

    环境:centos6.7https://github.com/vinta/awesome-pythonhttps://github.com/PyMySQL/PyMySQLhttps://github. ...

  8. C#基础篇四数组

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace P01A ...

  9. java5新特性-加强for循环

    本文目标是加强for循环和普通for循环的比较.阅读本文大概3-5分钟 刚开始学习编程语言的时候接触了三种循环方式 1. for 常用 2. while 较常用 3 do ... while 不常用 ...

  10. jQuery同步Ajax带来的UI线程阻塞问题及解决方法

    遇到了同步Ajax引起的UI线程阻塞问题,在此记录一下. 事情起因是这样的,因为页面上有多个相似的异步请求动作,本着提高代码可重用性的原则,我封装了一个名为getData的函数,它接收不同参数,只负责 ...