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 ...
随机推荐
- Controller中添加一个异步的Action
给一段示例代码: public Task<ActionResult> TbReport(string code) { return Task.Factory.StartNew(() =&g ...
- vmware共享文件夹
环境: VMware Workstation 11.0 虚拟机中的系统:Ubuntu 16.04 物理机:window 7 安装好vmware tools后在 /mnt/hgfs 里没有东西,是空白的 ...
- AbelSu玩Kotlin
Kotlin是一门基于JVM的编程语言,它正成长为Android开发中用于替代Java语言的继承者. Kotlin是由JetBrains创建的基于JVM的编程语言,IntelliJ正是JetBrain ...
- Feeling_2018_5_22
“我打你,你会走吗?” “不会!!” “我骂你,你会走吗?” “不会!!” “那我不爱你了,你会走吗?” “会.”
- [C/C++标准库]_[初级]_[转换UTC时间到local本地时间]
场景 1.如果有面向全球用户的网站, 一般在存储时间数据时存储的是UTC格式的时间, 这样时间是统一的, 并可以根据当地时区来进行准确的转换. 2.存储本地时间的问题就在于如果换了时区, 那么显示的时 ...
- StringUtils类方法归纳
StringUtils方法概览 IsEmpty/IsBlank - checks if a String contains text IsEmpty/IsBlank – 检查字符串是否有内容. Tri ...
- JS跨浏览器的事件处理
1. 事件流 事件:用户或浏览器自身执行的某种动作.如click(点击事件).mouse***(鼠标事件). 事件流:页面中接收事件的顺序,也可理解为事件在页面中传播的顺序. DOM事件流包括三个阶段 ...
- C#用Infragistics 导入导出Excel(一)
最近项目中有数据的导入导出Excel的需求,这里做简单整理. 公司用的是Infragistics的产品,付费,不需要本地安装Office. 有需要的朋友可以下载 Infragistics.2013.2 ...
- vuex实践之路——笔记本应用(一)
首先使用vue-cli把环境搭建好. 介绍一下应用的界面. App.vue根组件,就是整个应用的最外层 Toolbar.vue:最左边红色的区域,包括三个按钮,添加.收藏.删除. NoteList.v ...
- Mac 上flink的安装与启动
在Mac 上安装flink,需要通过Homebrew安装的 1.howmebrew的安装方式,在终端粘贴以下命令,或者去官网https://brew.sh/index_zh-cn 找到此代码复制粘贴到 ...