#线段树#CF438D The Child and Sequence】的更多相关文章

题目大意 区间取模,区间求和,单点修改. 分析 其实算是一道蛮简单的水题. 首先线段树非常好解决后两个操作,重点在于如何解决区间取模的操作. 一开始想到的是暴力单点修改,但是复杂度就飙到了\(mnlogn\),直接爆炸. 但是重新看到了题目中给出的4s的操作,说明,我们可以优化单点修改的操作. 那么我们顺便维护一下区间的最大值,如果当前的区间的最大值是小于mod数的,那么这个区间内的所有数都是没有必要mod的. 后面随着数据的越来越大,那么就可以剪去不必要的操作. 代码 #include <bi…
题目链接:CF原网  洛谷 题目大意:维护一个长度为 $n$ 的正整数序列 $a$,支持单点修改,区间取模,区间求和.共 $m$ 个操作. $1\le n,m\le 10^5$.其它数均为非负整数且 $\le 10^9$. 居然被这道水题卡了那么久…… 主要难点就是取模操作. 我们发现一个数 $x$ 模 $i(1\le i\le x)$: $i\le\lfloor\frac{x}{2}\rfloor$ 时:余数小于除数,所以答案小于 $\lfloor\frac{x}{2}\rfloor$. $i…
一道CF线段树好题. 前置芝士 线段树:一个很有用数据结构. 势能分析:用来证明复杂度,其实不会也没什么关系啦. 具体做法 不难发现,对于一个数膜一个大于它的数后,这个数至少减少一半,每个数最多只能被膜\(\log_2N\)次,所以就可以暴力修改了,如果当前子树的最大值也比膜数要大,那这个膜数肯定就没什么用了,所以可以再记录一个区间最大值. 代码 #include<bits/stdc++.h> #define rap(i,first,last) for(int i=first;i<=la…
给定数列,区间查询和,区间取模,单点修改. n,m小于10^5 ...当区间最值小于模数时,就直接返回就好啦~ #include<cstdio> #include<iostream> #define R register int #define ls (tr<<1) #define rs (tr<<1|1) using namespace std; inline long long g() { register ,fix=; register :fix; +…
外国人的数据结构题真耿直 唯一有难度的操作就是区间取模,然而这个东西可以暴力弄一下,因为一个数$x$被取模不会超过$logn$次. 证明如下(假设$x Mod   y$): 如果$y \leq \frac{x}{2}$那么$x$取模之后会小于$\frac{x}{2}$,而如果$y > \frac{x}{2}$时,$x$取模之后一定也会小于$\frac{x}{2}$ 然后就暴力一个一个取过去就好了,还有一个算是剪枝的优化,我们可以顺便维护一下区间最大值,如果区间最大值都小于当前的模数的话,那么就直…
点此看题面 大致题意: 给你一个序列,让你支持区间求和.区间取模.单点修改操作. 区间取模 区间求和和单点修改显然都很好维护吧,难的主要是区间取模. 取模标记无法叠加,因此似乎只能暴力搞? 实际上,我么先考虑一个结论: 一个数\(x\)向一个不大于它的数\(p\)取模,所得结果必然小于\(\frac x2\). 证明: 当\(p\le\frac x2\)时,由于\(x\%p<p\),所以\(x\%p<\frac x2\). 当\(p>\frac x2\)时,由于\(p\le x\),所以…
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 time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output 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…
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 things were lost, in particular the favorite sequence of Picks. Fortunately, Picks remembers how to repair the seq…