![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
差分数组
black-hole6
这个作者很懒,什么都没留下…
展开
-
差分数组原理及应用
一、差分数组的定义及用途1.定义:对于已知有n个元素的离线数列d,我们可以建立记录它每项与前一项差值的差分数组f:显然,f[1]=d[1]-0=d[1];对于整数i∈[2,n],我们让f[i]=d[i]-d[i-1]。2.简单性质:(1)计算数列各项的值:观察d[2]=f[1]+f[2]=d[1]+d[2]-d[1]=d[2]可知,数列第i项的值是可以用差分数组的前i项的和计算的,...原创 2018-12-15 10:34:55 · 484 阅读 · 0 评论 -
牛客练习赛34-C-little w and Segment Coverage(差分数组)
链接:https://ac.nowcoder.com/acm/contest/297/C来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288K64bit IO Format: %lld题目描述小w有m条线段,编号为1到m。用这些线段覆盖数轴上的n个点,编号为1到n。第i条线段覆盖数轴上的区间是L[i],R[i]...原创 2018-12-15 10:57:34 · 326 阅读 · 0 评论 -
HDU-1556-Color the ball (线段树和差分数组两种解法)
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?Input每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数...原创 2018-12-15 11:21:52 · 1415 阅读 · 0 评论 -
CodeForces - 1110E-Magic Stones(差分+思维)
Grigory has nn magic stones, conveniently numbered from 11 to nn. The charge of the ii-th stone is equal to cici.Sometimes Grigory gets bored and selects some inner stone (that is, some stone with i...原创 2019-02-08 11:42:36 · 469 阅读 · 0 评论 -
C - 思考使用差分简化区间操作
FJ's N (1 ≤ N ≤ 10,000) cows conveniently indexed 1..N are standing in a line. Each cow has a positive integer height (which is a bit of secret). You are told only the height H (1 ≤ H ≤ 1,000,000) of ...原创 2019-02-20 01:06:32 · 465 阅读 · 0 评论