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…
外国人的数据结构题真耿直 唯一有难度的操作就是区间取模,然而这个东西可以暴力弄一下,因为一个数$x$被取模不会超过$logn$次. 证明如下(假设$x Mod   y$): 如果$y \leq \frac{x}{2}$那么$x$取模之后会小于$\frac{x}{2}$,而如果$y > \frac{x}{2}$时,$x$取模之后一定也会小于$\frac{x}{2}$ 然后就暴力一个一个取过去就好了,还有一个算是剪枝的优化,我们可以顺便维护一下区间最大值,如果区间最大值都小于当前的模数的话,那么就直…
给定数列,区间查询和,区间取模,单点修改. 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; +…
一道CF线段树好题. 前置芝士 线段树:一个很有用数据结构. 势能分析:用来证明复杂度,其实不会也没什么关系啦. 具体做法 不难发现,对于一个数膜一个大于它的数后,这个数至少减少一半,每个数最多只能被膜\(\log_2N\)次,所以就可以暴力修改了,如果当前子树的最大值也比膜数要大,那这个膜数肯定就没什么用了,所以可以再记录一个区间最大值. 代码 #include<bits/stdc++.h> #define rap(i,first,last) for(int i=first;i<=la…
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…
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…
题面 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…
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…
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…
D - The Child and Sequence 思路: 因为有区间取模操作所以没法用标记下传: 我们发现,当一个数小于要取模的值时就可以放弃: 凭借这个来减少更新线段树的次数: 来,上代码: #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 100005 #define ll lo…
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…
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…
点此看题面 大致题意: 给你一个序列,让你支持区间求和.区间取模.单点修改操作. 区间取模 区间求和和单点修改显然都很好维护吧,难的主要是区间取模. 取模标记无法叠加,因此似乎只能暴力搞? 实际上,我么先考虑一个结论: 一个数\(x\)向一个不大于它的数\(p\)取模,所得结果必然小于\(\frac x2\). 证明: 当\(p\le\frac x2\)时,由于\(x\%p<p\),所以\(x\%p<\frac x2\). 当\(p>\frac x2\)时,由于\(p\le x\),所以…
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…
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…
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…
题目描述 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.…
题目链接:http://codeforces.com/problemset/problem/438/D 给你n个数,m个操作,1操作是查询l到r之间的和,2操作是将l到r之间大于等于x的数xor于x,3操作是将下标为k的数变为x. 注意成段更新的时候,遇到一个区间的最大值还小于x的话就停止更新. #include <iostream> #include <cstdio> #include <cstring> using namespace std; typedef __…
Codeforces Round #250 (Div. 1)D:http://codeforces.com/problemset/problem/438/D 题意:给你一个序列,然后有3种操作 1x y.表示查询[x,y]之间的区间和,2 x y z表示把[x y]内的数%z,3x y,表示把第x个数变成y. 题解:肯定是用线段树来维护,但是一开始想不到维护什么统计量,对于区间取模,没办法用lazy标记,更新到第的话,肯定会T.后来,认为既然没办法用lazy,那么只能用别的方法来优化更新.发现每…
题意:给定一个n个数的序列,完成以下3个操作: 1.给定区间求和 2.给定区间对x取模 3.单点修改 对一个数取模,这个数至少折半.于是我们记一个最大值max,如果x>max则不做处理. #include<stdio.h> #include<algorithm> using namespace std; #define MAXN 1000000+10 typedef long long LL; ]; int n,m; LL a[MAXN]; void build(int k,…
[原题题面]传送门 [大致题意] 给定一个长度为n的非负整数序列a,你需要支持以下操作: 1:给定l,r,输出a[l]+a[l+1]+…+a[r]. 2:给定l,r,x,将a[l],a[l+1],…,a[r]对x取模. 3:给定k,y,将a[k]修改为y. [数据范围] n,m<=100000,a[i],x,y<=109. [题解大意] 维护最大值和区间和,然后通过最大值有没有超过x来判断需不需要取模操作. [code] #include<bits/stdc++.h> using…
题意 题目链接 单点修改,区间mod,区间和 Sol 如果x > mod ,那么 x % mod < x / 2 证明: 即得易见平凡, 仿照上例显然, 留作习题答案略, 读者自证不难. 反之亦然同理, 推论自然成立, 略去过程Q.E.D., 由上可知证毕. 然后维护个最大值就做完了.. 复杂度不知道是一个log还是两个log,大概是两个吧(线段树一个+最多改log次.) #include<bits/stdc++.h> #define Pair pair<int, int&g…
传送门 线段树维护区间取模,单点修改,区间求和. 这题老套路了,对一个数来说,每次取模至少让它减少一半,这样每次单点修改对时间复杂度的贡献就是一个log" role="presentation" style="position: relative;">loglog,所以维护区间最大值剪枝,然后每次单点暴力取模,这样的话时间复杂度为O(nlogn)" role="presentation" style="posi…
题意: 给定一个长度为n的非负整数序列a,你需要支持以下操作:1)给定l,r,输出a[l] + a[l+1] + ... + a[r] 2)给定l,r,x, 将a[l].a[l+1]......a[r]对x取模 3)给定k,y,将a[k]修改为y n, m <= 100000,a[i], x, y <= 109 对于操作(1)(3)非常简单,线段树基本操作 问题是操作(2),显然的是我们不能对区间和取模,这样就很难受 但是我们可以想到,一个数若是比模数小,就不需要取模,而一个数w有效取模次数最…
\(\\\) \(Description\) 维护长为 \(N\) 的数列,\(M\)次操作,支持单点修改,区间取模,查询区间和. \(N,M\le 10^5\) \(\\\) \(Solution\) 线段树单点修改直接改,直接维护区间和就好. 关于取模,显然的优化是,当前节点代表区间最大值如果小于模数就停止递归. 事实上我们只需要这样做,甚至连区间取模的 tag 都不用. 因为一个数变为 \(1\) 至多需要 \(log\) 次取模,所以每个数至多被有效操作 \(log\) 次,然而修改是单…
题意:对数列有三种操作: 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(…
赛前任务 tags:任务清单 前言 现在xzy太弱了,而且他最近越来越弱了,天天被爆踩,天天被爆踩 题单不会在作业部落发布,所以可(yi)能(ding)会不及时更新 省选前的练习莫名其妙地成为了Noip前的杂题训练,我也很无奈啊 做完了的扔最后,欢迎好题推荐 这么多题肯定是完不成了,能多做一道是一道吧 DP yyb真是强得不要不要的辣:http://www.cnblogs.com/cjyyb/category/1036536.html [ ] [SDOI2010]地精部落 https://www…
A. The Child and Homework 注意仔细读题,WA了好多次,=_= #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ; ][maxn]; ], r[]; bool cmp(int a, int b) { return l[a] < l[b]; } int main() { //freopen("in.txt", &q…