Rikka with Prefix Sum 题目描述 Prefix Sum is a useful trick in data structure problems. For example, given an array A of length n and m queries. Each query gives an interval [l,r] and you need to calculate . How to solve this problem in O(n+m)? We can ca…
Rikka with Prefix Sum 题意: 给出一个数组a,一开始全为0,现在有三种操作: 1. 1 L R W,让区间[L,R]里面的数全都加上W: 2. 2 将a数组变为其前缀和数组: 3. 3 L R 询问此时a数组区间[L,R]的和. 题解: 第一种操作我们可以简化为a[L]+W,a[R+1]-W,利用差分数组的思想. 接下来这一步使关键,考虑i这个位置有值a[i],然后经过多次2操作对后面的值的贡献,先可以从a[i]=1考虑,然后推广就是了= = 发现1这个数对…
链接:https://www.nowcoder.com/acm/contest/148/D来源:牛客网 Prefix Sum is a useful trick in data structure problems. For example, given an array A of length n and m queries. Each query gives an interval [l,r] and you need to calculate . How to solve this pro…