题意:

 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. jquery jqzoom插件练习

    <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> ...

  2. rpm yum apt-get redhat centos ubuntu

    rpm是由红帽公司开发的软件包管理方式,使用rpm我们可以方便的进行软件的安装.查询.卸载.升级等工作.但是rpm软件包之间的依赖性问题往往会很繁琐,尤其是软件由多个rpm包组成时.Yum(全称为 Y ...

  3. pdflush机制

    在做进程安全监控的时候,拍脑袋决定的,如果发现一个进程在D状态时,即TASK_UNINTERRUPTIBLE(不可中断的睡眠状态),时间超过了8min,就将系统panic掉.恰好DB组做日志时,将整个 ...

  4. 利用Cydia Substrate进行Android HOOK

    Cydia Substrate是一个代码修改平台.它可以修改任何主进程的代码,不管是用Java还是C/C++(native代码)编写的.而Xposed只支持HOOK app_process中的java ...

  5. 20155317《网络对抗》Exp4 恶意代码分析

    20155317<网络对抗>Exp4 恶意代码分析 基础问题回答 如果在工作中怀疑一台主机上有恶意代码,但只是猜想,所有想监控下系统一天天的到底在干些什么.请设计下你想监控的操作有哪些,用 ...

  6. 20155339 Exp5 MSF基础应用

    20155339 Exp5 MSF基础应用 基础问题回答 用自己的话解释什么是exploit,payload,encode. 答: exploit是通过自己选择的漏洞和载荷进行攻击的一个过程. pay ...

  7. python 回溯法 子集树模板 系列 —— 1、8 皇后问题

    问题 8×8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行.同一列或同一斜线上,问有多少种摆法. 分析 为了简化问题,考虑到8个皇后不同行,则每一行放置一个皇后,每一行的 ...

  8. libgdx学习记录11——平铺地图TiledMap

    地图对于游戏场景十分重要,很多游戏都需要对地图进行编辑,可使用TileMap进行编辑并生成对应的tmx格式地图文件. 编辑好后,可通过TmxMapLoader来读取地图文件.可通过一个正交相机Otho ...

  9. 菜鸟凉经(华为、firehome、大华)

    面试通知都是前一天来的,准备的时间很少,所以表现也不是特别满意,来看面经吧: 华为一面(IT应用工程师): 1.自我介绍:(华为面试都是1对1,面前的是个温柔的小哥,挺放松的) 2.你主要会的it技术 ...

  10. 深度学习目标检测综述推荐之 Xiaogang Wang ISBA 2015

    一.INTRODUCTION部分 (1)先根据时间轴讲了历史 (2)常见的基础模型 (3)讲了深度学习的优势 那就是feature learning,而不用人工划分的feature engineeri ...