题意 题目链接 单点修改,区间mod,区间和 Sol 如果x > mod ,那么 x % mod < x / 2 证明: 即得易见平凡, 仿照上例显然, 留作习题答案略, 读者自证不难. 反之亦然同理, 推论自然成立, 略去过程Q.E.D., 由上可知证毕. 然后维护个最大值就做完了.. 复杂度不知道是一个log还是两个log,大概是两个吧(线段树一个+最多改log次.) #include<bits/stdc++.h> #define Pair pair<int, int&g…
Code: #include<algorithm> #include<cstdio> #include<cstring> #define ll long long #define setIO(s) freopen(s".in","r",stdin) #define maxn 2000000 #define lson (now<<1) #define rson ((now<<1)|1) using names…
题目描述 给出一个长度为 $n$ 的序列,支持 $m$ 次操作,操作有四种:区间加.区间下取整除.区间求最小值.区间求和. $n\le 100000$ ,每次加的数在 $[-10^4,10^4]$ 之间,每次除的数在 $[2,10^9]$ 之间. 题解 线段树+均摊分析 和 [uoj#228]基础数据结构练习题 类似的均摊分析题. 对于原来的两个数 $a$ 和 $b$ ( $a>b$ ) ,原来的差是 $a-b$ ,都除以 $d$ 后的差是 $\frac{a-b}d$ ,相当于差也除了 $d$…
题目描述 给出一个长度为 $n$ 的序列,支持 $m$ 次操作,操作有三种:区间加.区间开根.区间求和. $n,m,a_i\le 100000$ . 题解 线段树+均摊分析 对于原来的两个数 $a$ 和 $b$ ( $a>b$ ) ,开根后变成 $\sqrt a$ 和 $\sqrt b$ ,它们的差从 $a-b$ 变成了 $\sqrt a-\sqrt b$ . 又有 $(\sqrt a-\sqrt b)(\sqrt a+\sqrt b)=a-b$ ,因此开方后的差小于原来差的开方. 而当区间差为…
D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/438/problem/D Description At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important…
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite sequence of Picks. Fortunately, Picks remembers how to repair the sequence. Initi…
D. 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 him. A lot of important things were lost, in particular the favorite sequence of Picks. Fortunately, Picks remembers how t…
题意:对数列有三种操作: Print operation l, r. Picks should write down the value of . Modulo operation l, r, x. Picks should perform assignment a[i] = a[i] mod x for each i (l ≤ i ≤ r). Set operation k, x. Picks should set the value of a[k] to x (in other words…
传送门 题目大意: 给你一个序列,要求在序列上维护三个操作: 1)区间求和 2)区间取模 3)单点修改 这里的操作二很讨厌,取模必须模到叶子节点上,否则跑出来肯定是错的.没有操作二就是线段树水题了. 既然必须模到叶子节点,那我们就模咯. 显然,若$b<c$,则$b%c=b$. 因此我们同时维护一个区间最大值,若某区间内最大值小于模数,就把该分支剪掉. 若$a=b%c$,那么肯定有$a \leq \frac{b}{2}$成立. 也就是说,一个数最多被模$\log_2 x$次.总的时间复杂度为$O(…
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4127 题解 首先区间绝对值和可以转化为 \(2\) 倍的区间正数和 \(-\) 区间和.于是问题就转化为区间正数和. 因为每一次增加的量 \(d \geq 0\),所以每一个数只会被从负数变成正数一次.也就是说,从负变正的操作最多出现 \(n\) 次. 于是我们考虑在线段树上对于从负数变成正数的操作暴力修改. 如何判断一个区间内有负数变成正数的操作呢.令 \(c\) 表示这个区间的最大负数.…