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 ...
随机推荐
- jqgrid 单击行启用行编辑,切换行保存原编辑行
为了加速表格互动编辑,我们往往希望通过选中行就触发了行编辑,完成行编辑后,再选中另一个行做编辑,同时上一个编辑行被自动保存,直至完成需要的编辑内容. 页面效果可能如下: 1)设置需要编辑的列 edit ...
- Hadoop详细配置教程
windows下采用PuTTY或者Xshell连接远程主机 mac用终端连接远程linux主机:ssh user@hostname user 为 linux 服务器的管理员名称 hostname 为 ...
- WPF save listbox config
UI <Grid x:Class="WzlyTool.ReplyContentUI" xmlns="http://schemas.microsoft.com/win ...
- 20155204《网络对抗》Exp8 Web基础
20155204<网络对抗>Exp8 Web基础 一.基础问题回答 1.什么是表单 表单在网页中主要负责数据采集功能.一个表单有三个基本组成部分: 表单标签:这里面包含了处理表单数据所用C ...
- Luogu P2341 [HAOI2006]受欢迎的牛
这道题应该也是经典的SCC题了吧 印象中不知道在在班里上课的时候在紫书,ACM竞赛的那些书上看到多少次(有点奇怪) 首先思路很明显,就是要找出有多少个点,以它们为起点可以遍历整个图 首先考虑一种情况, ...
- Luogu P1983 车站分级
(一周没写过随笔了) 这道题有坑! 看到题目,发现这么明显(??)的要求顺序,还有什么想法,拓扑! 将每条路范围内等级大于等于它的点(不能重复(坑点1))和它连一条边,注意起点终点都要有(坑点2),然 ...
- 汇编 REPE/REPZ 指令,CMPSB指令
知识点: REPE/REPZ 指令 CMPSB 指令 一.CMPSB //cmp //sub //SCASB//scasw//scasd cmp byte ptr [edi],al //对标志位的 ...
- Linux内核中_IO,_IOR,_IOW,_IOWR宏的用法
#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0) #define _IOR(type,nr,size) _IOC(_IOC_RE ...
- 德哥的PostgreSQL私房菜 - 史上最屌PG资料合集
德哥的PostgreSQL私房菜 - 史上最屌PG资料合集
- redis见解
http://blog.csdn.net/zhiguozhu/article/details/50517527Redis原生session与redis中的session区别原生session在服务器上 ...