题意:给你数组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 equals to r - l + 1),或者 2 i b:把第i个换成b

思路:用一个树状数组存i的前缀和,再用一个树状数组存(n - i + 1)*a[ i ]的前缀和,这样算出后面那个的区间差减去前一个的区间差的某个倍数就会成为答案。

代码:

#include<queue>
#include<cstring>
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<vector>
#include<cstdio>
#include<iostream>
#include<algorithm>
typedef long long ll;
const int maxn = + ;
const int seed = ;
const ll MOD = 1e9 + ;
const int INF = 0x3f3f3f3f;
using namespace std;
ll sum[][maxn], a[maxn];
ll n;
int lowbit(int x){
return x&(-x);
}
void update(int x, ll v, int id){
for(int i = x; i <= n; i += lowbit(i)){
sum[id][i] += v;
}
}
ll query(int x, int id){
ll cnt = ;
for(int i = x; i > ; i -= lowbit(i)){
cnt += sum[id][i];
}
return cnt;
}
int main(){
ll q;
while(~scanf("%lld%lld", &n, &q)){
memset(sum, , sizeof(sum));
for(int i = ; i <= n; i++){
scanf("%lld", &a[i]);
update(i, a[i], );
update(i, a[i] * (n - i + ), );
}
while(q--){
ll u, v, w;
scanf("%lld%lld%lld", &u, &v, &w);
if(u == ){
printf("%lld\n", query(w, ) - query(v - , ) - (n - w) * (query(w, ) - query(v - , )));
}
else{
update(v, -a[v] + w, );
update(v, (-a[v] + w) * (n - v + ), );
a[v] = w;
}
}
}
return ;
}

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

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

    https://nanti.jisuanke.com/t/31460 题意 两个操作.1:查询区间[l,r]的和,设长度为L=r-l+1, sum=a[l]*L+a[l+1]*(L-1)+...+a[ ...

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

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

  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. 2018/03/29 每日一个Linux命令 之 ping

    ping 用于测试两及其网络是否通 主要用于检测网络是否通畅. -- 具体语法 ping [-dfnqrRv][-c<完成次数>][-i<间隔秒数>][-I<网络界面&g ...

  2. 洛谷P3599 Koishi Loves Construction 构造

    正解:构造 解题报告: 传送门! 这题俩问嘛,就分成两个问题港QwQ 就按顺序趴,先港第一问QwQ 首先要发现,n在膜n意义下就是0嘛 那作为前缀和的话显然它就只能放在第一个 然后再想下,发现,如果n ...

  3. Celery框架简单实例

    Python 中可以使用Celery框架 Celery框架是提供异步任务处理的框架,有两种用法,一种:应用程式发布任务消息,后台Worker监听执行,好处在于不影响应用程序继续执行.第二种,设置定时执 ...

  4. HTML5 脚本 语言代码 URL 符号实体 ASCII码 颜色

    1.HTML<noscript> 标签 <noscript> 标签提供无法使用脚本时的替代内容,比方在浏览器禁用脚本时,或浏览器不支持客户端脚本时. <noscript& ...

  5. Python 使用ctypes调用 C 函数

    在python中通过ctypes可以直接调用c的函数,非常简单易用 下面就一步一步解释用法吧,以Linux为例讲解. 1, 首先确定你的python支持不支持ctypes python2.7以后cty ...

  6. Bind()事件

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. jQ live用法

    我们给元素绑定单击事件.用得最多的都是$("#id").click(function(){}); 但我们动态添加的元素.这样绑定是不行的.必须借助live  $("#id ...

  8. Lintcode: Insert Node in a Binary Search Tree

    Given a binary search tree and a new tree node, insert the node into the tree. You should keep the t ...

  9. try except else

    try except 语句还有一个可选的else子句,如果使用这个子句,那么必须放在所有的except子句之后.这个子句将在try子句没有发生任何异常的时候执行.例如: for arg in sys. ...

  10. MySQL从删库到跑路_高级(六)——索引

    作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.索引简介 1.索引简介 索引(Index)是帮助MySQL高效获取数据的数据结构. 在MySQL中,索引属于存储 ...