https://nanti.jisuanke.com/t/31460

题意

两个操作。1:查询区间[l,r]的和,设长度为L=r-l+1, sum=a[l]*L+a[l+1]*(L-1)+...+a[r]。2:将第a个位置修改为b。

分析

变形一下,sum=a[l]*(r-l+1)+a[l+1]*(r-(l+1)-1)+...+a[r](r-r+1)=(r+1)*a[l]-a[l]*l。因此,可维护两个树状数组计算。至于更新操作,实质就是看变化前后的差值,变大就相当与加上差值,否则就是减。注意用longlong

#include<bits/stdc++.h>
const int maxn = 1e5 + ;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + ;
typedef long long ll;
ll c1[maxn],c2[maxn];
int a[maxn];
int lb(int x){ return x&-x; }
void add(ll c[],int x,ll d){
while(x<maxn){
c[x]+=d;
x+=lb(x);
}
}
ll sum(ll c[],int x){
ll res=;
while(x){
res+=c[x];
x-=lb(x);
}
return res;
}
ll query(int l,int r){
return (r+)*(sum(c1,r)-sum(c1,l-))-(sum(c2,r)-sum(c2,l-));
}
int main(){
int n,q;
int op,x,y;
scanf("%d%d",&n,&q);
for(int i=;i<=n;i++) {
scanf("%d",&x);
add(c1,i,x);
add(c2,i,1ll*i*x);
a[i]=x;
}
while(q--){
scanf("%d%d%d",&op,&x,&y);
if(op==){
printf("%lld\n",query(x,y));
}else{
add(c1,x,y-a[x]);
add(c2,x,1ll*x*(y-a[x]));
a[x]=y;
}
}
return ;
}

ACM-ICPC 2018 徐州赛区网络预赛 H Ryuji doesn't want to study (树状数组差分)的更多相关文章

  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. ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study (线段树)

    Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, ea ...

  3. ACM-ICPC 2018 徐州赛区网络预赛H Ryuji doesn't want to study(树状数组)题解

    题意:给你数组a,有两个操作 1 l r,计算l到r的答案:a[l]×L+a[l+1]×(L−1)+⋯+a[r−1]×2+a[r] (L is the length of [ l, r ] that ...

  4. ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study(树状数组)

    Output For each question, output one line with one integer represent the answer. 样例输入 5 3 1 2 3 4 5 ...

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

  6. ACM-ICPC 2018 徐州赛区网络预赛 G Trace(逆向,两颗线段树写法)

    https://nanti.jisuanke.com/t/31459 思路 凡是后面的轨迹对前面的轨迹有影响的,可以尝试从后往前扫 区间修改需要push_down,单点更新所以不需要push_up(用 ...

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

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

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

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

  9. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

随机推荐

  1. swoole多端口监听

    今天测试swoole写webserver实现多端口监听.记录下爬过的坑:关于tcp协议监听触发不到receive!!!!! 首先上服务端代码 class Http { /** * 服务实例 * @va ...

  2. 全民抵制“辱华”品牌秀,D&G神回复:呵呵~ 那不是我!

    ### 补发一下,前写天写的: 就在今天下午,有网友爆出知名品牌 Dolce&Gabbana(杜嘉班纳)的设计师兼创始人Stefano Gabbana在ins上公然发表辱华言论. 下面截图 可 ...

  3. 微信小程序访问豆瓣api403问题解决方发法

    微信小程序访问豆瓣api403问题解决方法一览:通过豆瓣api可以获取很多电影.书籍等的数据信息.昨晚上用微信小程序请求豆瓣api,竟然被豆瓣拒绝了.(豆瓣设置了小程序的访问权限):下面就跟着小编一起 ...

  4. 分布式 cephfs

    参考链接: http://docs.ceph.com/docs/mimic/cephfs/

  5. Golang 入门系列(三)Go语言基础知识汇总

    前面已经了 Go 环境的配置和初学Go时,容易遇到的坑,大家可以请查看前面的文章 https://www.cnblogs.com/zhangweizhong/category/1275863.html ...

  6. Elastic Stack初篇-Logstash

     一.Logstash简介      Logstash是一个开源数据收集引擎,具有实时管道功能.Logstash可以动态地将来自不同数据源的数据统一起来,并将数据标准化到你所选择的目的地. 二.Log ...

  7. .netcore mvc docker环境jenkins一键部署(DevOps)

    [前言] DevOps方面的文章很早之前就想分享了,挤出一点时间把前段时间搭建的一些提高开发效率的东西给大家分享一下吧. 本文介绍了一个.netcore mvc web项目,从项目push到githu ...

  8. windows下安装和使用scrapy

    首先,要确保已经正确安装了python环境,并安装了pip包 接着,打开cmd或者powershell ,输入命令 pip install scrapy .安装完之后 运行scrapy性能测试命令: ...

  9. PS制作漂亮紫色霓虹灯光文字

    一.新建画布,大小1500 * 950像素,分辨率为300,置入墙壁图像,大小适合. 二.调整图层的色阶,色相/饱和度. 三.新建文字图层,颜色为#a33e88,大小为103,字体为Beon Medi ...

  10. OracleSql语句学习(四)

    SELECT e.ename,m.ename,d.locFROM emp_weiyiji e JOIN emp_weiyiji m ON e.mgr=m.empnoJOIN dept_weiyiji ...