Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 97008   Accepted: 30285 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given…
http://poj.org/problem?id=3468 (题目链接) 题意 给出一个序列,要求维护区间修改与区间求和操作. Solution 多年以前学习的树状数组区间修改又忘记了→_→. 其实就是用树状数组维护一个差分序列${delta[i]}$,${delta[x]}$记录${[i,n]}$中每一个数的增量,每次修改${[l,r]}$就转化为了${delta[l]+=d,delta[r+1]-=d}$. 对于求和操作${[l,r]}$,其实就是${sum(x)-sum(y)}$,我们这…
题目大意: 2个操作 A.区间a b 增加 c B 查询a b; 注意事项:1.记住要清除标记 2.查询时要下放标记,但没必要向上更新 线段:自带的,不用建模 区间和性质:sum: /* WA 1次 以为不要LONG LONG */ #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <ctime> #include <algor…
1548:[例 2]A Simple Problem with Integers 题目描述 这是一道模板题. 给定数列 a[1],a[2],…,a[n],你需要依次进行 q 个操作,操作有两类: 1 l r x:给定 l,r,x,对于所有 i∈[l,r],将 a[i] 加上 x(换言之,将 a[l],a[l+1],…,a[r] 分别加上 x): 2 l r:给定 l,r,求 a[i]∑i=[l,r].​a[i] 的值(换言之,求 a[l]+a[l+1]+⋯+a[r] 的值). 输入格式 第一行包…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 149972   Accepted: 46526 题目链接:http://poj.org/problem?id=3468 Description: You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operation…
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval. In…
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval. In…
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval. In…
http://poj.org/problem?id=3468 _(:зゝ∠)_我又活着回来啦,前段时间太忙了写的题没时间扔上来,以后再说. [问题描述] 成段加某一个值,然后询问区间和. [思路] 讲一下pushdown和pushup出现的几个位置. pushup: (1)build的结尾,当叶子节点分别有对应的值后,它的父亲们就等于它们求和. (2)update的结尾,因为此时当前根的左右孩子已经更新了,故它也需要更新. pushdown(延迟标记): *pushdown会出现在一切要从当前结…
[题目链接] 点击打开链接 [算法] 本题用线段树很容易写,但是,笔者为了练习树状数组,就用树状数组的方法做了一遍 我们不妨引入差分数组c, 则sum(n) = c[1] + (c[1] + c[2]) + (c[1] + c[2] + c[3]) + ... + (c[1] + c[2] + c[3] + ... + c[n]) = n * c[1] + (n - 1) * c[2] + (n - 2) * c[3] + ... + c[n] = n * (c[1] + c[2] + c[3]…