题意:

 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 徐州赛区网络预赛的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 计蒜客 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 ...

  4. ACM-ICPC 2018 徐州赛区网络预赛(8/11)

    ACM-ICPC 2018 徐州赛区网络预赛 A.Hard to prepare 枚举第一个选的,接下来的那个不能取前一个的取反 \(DP[i][0]\)表示选和第一个相同的 \(DP[i][1]\) ...

  5. ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)

    传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...

  6. 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 ...

  7. ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track

    262144K   Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...

  8. 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 ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 D 杜教筛 前缀和

    链接 https://nanti.jisuanke.com/t/31456 参考题解  https://blog.csdn.net/ftx456789/article/details/82590044 ...

随机推荐

  1. 虚拟机VirtualBox安装MAC OS 10.12图文教程

    VirtualBox虚拟机安装Mac OS 10.12图文教程的准备 1.VirtualBox虚拟机 下载地址:https://www.virtualbox.org/ 特别提醒:推荐官方下载,安装Vi ...

  2. 第16章 STM32中断应用概览

    第16章     STM32中断应用概览 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fi ...

  3. 关于this指向,翻到的

    关于JavaScript函数执行环境的过程,IBM developerworks文档库中的一段描述感觉很不错,摘抄如下: “JavaScript 中的函数既可以被当作普通函数执行,也可以作为对象的方法 ...

  4. 在testbench从文件读入激励

    在验证verilog逻辑模块功能时候,我们可以从文件中读入激励,便于大规模的验证.文件中的数据我们可以用c++编写程序产生. 第一种读入文件的方法是用系统函数:$readmemb, readmemh, ...

  5. Android 下拉刷新上拉加载PullToRefresh

    https://github.com/823546371/PullToRefresh http://www.jianshu.com/p/0f5d0991efdc

  6. WPF 简易进度条效果

    最近做一个项目,看到以前同事写的进度条效果不错,所以,拿来简化了下,不炫,但是项目中还是够用的. 还是,先来看下调用以后的效果 1.因为ProgressbBar的Foreground显示不得不一样,所 ...

  7. POJ 3349&&3274&&2151&&1840&&2002&&2503

    (今天兴致大发学了Markdown,第一篇博客) 这次的主要都是hash的题目(当然这就意味这可以用map) hash的方式也有很多: 普通hash hash挂链 双hash以及自然溢出等 当然我还是 ...

  8. LNMP环境中WordPress程序伪静态解决方案

    LNMP环境是目前我们国内站长使用的Linux VPS配置环境中使用较多的.作为新手我们很可能会看到老左类似的"LNMP安装教程"然后依葫芦画瓢的去安装VPS.我们是否有发现环境中 ...

  9. HTML基础之HTML标签

    前端的三把利器 HTML:赤裸的一个人 CSS:华丽的衣服 JS/JavaScript:赋予这个人的行为,也就是动起来 HTML(超文本标记语言) html代码实际上就是一套能够被浏览器所识别的规则代 ...

  10. WebStorm安装

    用到的链接: WebStorm官网:https://www.jetbrains.com/webstorm 破解补丁与注册码网址:http://idea.lanyus.com/ 有条件的朋友请购买正版. ...