题意:给你数组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. 【JMeter】如何用JMeter进行压力测试

    [JMeter]如何用JMeter进行压力测试(调试脚本已再猪猪微信的收藏中进行了收藏哦,名字叫exam-wow.jmx) 一.用badboy录制压测过程形成脚本另存为jmeter格式文档. 二.JM ...

  2. wordpress如何正确自动获取中文日志摘要

    WordPress 函数 get_the_excerpt() 可以获取日志的摘要,如果没有摘要,它会自动获取内容,并且截取.但是由于无法正确统计中文字符数,我爱水煮鱼撰写了下面这个函数来解决这个问题. ...

  3. 如何删除帝国cms面包屑导航中首页链接的/index.html

    前面一篇"帝国cms面包屑导航的首页链接锚文本改成关键字"中xmyanke有写到改首页链接的方法,但是感觉比较麻烦,这里就说说如何删除帝国cms面包屑导航中首页链接的/index. ...

  4. 上传指定url文件到阿里云oss

    好处是不用下载到本地,也不用删除本地文件.省事! 先下载阿里云官方代码  https://github.com/aliyun/aliyun-oss-csharp-sdk 引用其中的 aliyun-os ...

  5. csv文件的读写

    # -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. "&quo ...

  6. 开源的挖矿软件,sha256

    http://cryptomining-blog.com/tag/sha-256d-miner/ https://github.com/cbuchner1/CudaMiner/blob/master/ ...

  7. Spark2.x学习笔记:Spark SQL的SQL

    Spark SQL所支持的SQL语法 select [distinct] [column names]|[wildcard] from tableName [join clause tableName ...

  8. [py]戏说python面向对象细节

    面向对象圣经 认识面向对象 什么是面向对象? 有什么实在的好处? 被坑了这么多年,没弄清楚和面向过程有啥切身的区分 我以为这都是大学老师的错. 没把我们启蒙好. 这么多年深受其害. 总结起来三个字: ...

  9. POJ2983 Is the Information Reliable?

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=267#problem/B                        B -  ...

  10. 谷歌浏览器:audio如何隐藏下载按钮

    当我们使用原生的audio标签时,可以看到如下的效果. 那么如何让下载按钮隐藏掉呢? 1. controlsList="nodownload" // 这个方法只支持 Chrome ...