Ryuji doesn't want to study 2018 徐州赛区网络预赛
题意:
1、区间求
a[l]×L+a[l+1]×(L−1)+⋯+a[r−1]×2+a[r](L is the length of [ l, r ] that equals to r - l + 1)
2、单点修改
解析:
只有这两个操作 并且区间求得值与前缀和极为相似
所以嘛 就要想到树状数组
树状数组能够维护前缀和 所以区间 [ l, r ] 就是r的前缀和减去l的前缀和
但每个a[i]的系数都不同 求前缀和无用。。所以要想到化简一下 把每个a[i]的系数都化为一样的或者定量
由上面的式子化简一下就变为
(∑ri=la[i]*(n−i+1))−(n−r)*∑ri=la[i]
对于每个a[i]我们合并一下系数 是不是就是上式的系数
所以维护两个前缀和 一个a[i] 和 一个 (n-i+1)*a[i]
输出时 减就可以了
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
const int maxn = 1e5+, INF = 0x7fffffff;
typedef long long LL;
LL cc[maxn], hh[maxn], A[maxn];
int n, q;
LL lowbit(LL x)
{
return x & -x;
} void add(LL x, LL y, LL yy)
{
for(LL i=x; i<=n; i+=lowbit(i))
cc[i] += y, hh[i] += yy;
} LL get_sum1(LL x)
{
LL res = ;
for(LL i=x; i>; i-=lowbit(i))
res += cc[i];
return res;
}
LL get_sum2(LL x)
{
LL res = ;
for(LL i=x; i>; i-=lowbit(i))
res += hh[i];
return res;
} int main()
{
cin >> n >> q;
for(LL i=; i<=n; i++)
{
cin >> A[i];
add(i, A[i], (n-i+)*A[i]);
}
while(q--)
{
int temp, a, b;
cin>> temp >> a >> b;
if(temp == )
{
LL res1 = get_sum1(b) - get_sum1(a-);
LL res2 = get_sum2(b) - get_sum2(a-);
cout<< res2 - (n-b)*res1 <<endl;
}
else
{
add(a, b-A[a], (n-a+)*(b-A[a]));
A[a] = b;
}
}
return ;
}
Ryuji doesn't want to study 2018 徐州赛区网络预赛的更多相关文章
- ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study
262144K Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...
- Ryuji doesn't want to study 2018徐州icpc网络赛 树状数组
Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, ea ...
- 计蒜客 1460.Ryuji doesn't want to study-树状数组 or 线段树 (ACM-ICPC 2018 徐州赛区网络预赛 H)
H.Ryuji doesn't want to study 27.34% 1000ms 262144K Ryuji is not a good student, and he doesn't wa ...
- ACM-ICPC 2018 徐州赛区网络预赛(8/11)
ACM-ICPC 2018 徐州赛区网络预赛 A.Hard to prepare 枚举第一个选的,接下来的那个不能取前一个的取反 \(DP[i][0]\)表示选和第一个相同的 \(DP[i][1]\) ...
- ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)
传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...
- ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE
In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...
- ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track
262144K Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...
- ACM-ICPC 2018 徐州赛区网络预赛 I. Characters with Hash
Mur loves hash algorithm, and he sometimes encrypt another one's name, and call him with that encryp ...
- ACM-ICPC 2018 徐州赛区网络预赛 D 杜教筛 前缀和
链接 https://nanti.jisuanke.com/t/31456 参考题解 https://blog.csdn.net/ftx456789/article/details/82590044 ...
随机推荐
- shell杂记
(本文将持续更新)从2015年9月25日开始正式学习linux类的东西. 书籍入门:UNIX.Shell编程24学时教程(中文版).Linux与UNIX Shell编程指南.shell十三问.LINU ...
- group by having 和where区别联系
原文参考:http://www.51ou.com/browse/msyql/43081.html having 和 where 参考 http://blog.csdn.net/yexudengzhid ...
- stm32中assert_param的用法说明
stm32中assert_param的用法说明 首先是要知道条件判断语句 这个运算符分成三部分: (条件) ? (条件成立执行部分) :(条件不成立执行部分) 就这么简单 例如:a=(x>y ...
- 20155330 《网络攻防》Exp1 PC平台逆向破解(5)M
20155330 <网络攻防>Exp1 PC平台逆向破解(5)M 实践目标 运行pwn1可执行文件中的getshell函数,学习如何注入运行任何Shellcode 本次实践的对象是一个名为 ...
- HTTPUTILS
maven依赖 <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId&g ...
- Verilog中的有符号计算之认知补码
Verilog中的有符号计数,一般是自己定义的而不是像C语言之类的定义一个有符号变量就好了.所以,要想在FPGA的世界里随心所欲的进行有符号运算,必须先对补码有一个很好的认知,然后再注意Verilog ...
- Eclipse中Svn插件配置
1. Svn插件配置教程 http://www.cnblogs.com/ruiati/p/3584120.html 2. Svn插件使用教程 http://wenku.baidu.com/link?u ...
- Hadoop日记Day16---命令行运行MapReduce程序
一.代码编写 1.1 单词统计 回顾我们以前单词统计的例子,如代码1.1所示. package counter; import java.net.URI; import org.apache.hado ...
- IP 解析器(IpParser) test 和 生产环境 实现
注意:之前我maven居然没有引入 StringUtils 的包,然后引入了一个路径类似,但其实包路径不一样的 StringUtils ,居然是划掉的状态,像这样 StringUtils ,这个其实不 ...
- SpringBoot日记——MQ消息队列整合(一)
除了之前讲到的缓存,我们还会用到消息队列来存储一些消息,为了提升系统的异步性能等等: 消息服务有两个概念需要知道:消息代理-message broker,目的地-destination.消息发送由代理 ...