Output

For each question, output one line with one integer represent the answer.

样例输入

5 3
1 2 3 4 5
1 1 3
2 5 0
1 4 5

样例输出

10
8
两个树状数组一个维护a[i]前缀合,一个维护(n-i+1)*a[i]前缀和。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
typedef unsigned long long ll;
ll sum[],n,m;
ll pos[];
ll a[];
void add(int x,ll val){
for(int i=x;i;i-=lowbit(i))
sum[i]+=val;
}
ll query(int x){
ll ans=;
for(int i=x;i<=;i+=lowbit(i))
ans+=sum[i];
return ans;
}
void add_one(int x,ll val){
for(int i=x;i;i-=lowbit(i))
pos[i]+=val;
}
ll query_one(int x){
ll ans=;
for(int i=x;i<=;i+=lowbit(i))
ans+=pos[i];
return ans;
}
int main()
{
while(scanf("%lld%lld",&n,&m)!=EOF)
{
memset(sum,,sizeof(sum));
memset(pos,,sizeof(pos));
memset(a,,sizeof(a));
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
add(i,1ll*a[i]*(n-i+));
add_one(i,a[i]);
}
while(m--){
ll op,x,y;
scanf("%lld%lld%lld",&op,&x,&y);
if(op==)
{
ll l=query(x);
ll r=query(y+);
ll u=query_one(x);
ll d=query_one(y+);
//printf("%lld\n",u-d);
printf("%lld\n",l-r-(1ll*(n-y)*(u-d)));
}
else{
add(x,1ll*(-)*a[x]*(n-x+));
add(x,1ll*(n-x+)*y);
add_one(x,1ll*(-)*a[x]);
a[x]=y;
add_one(x,1ll*a[x]);
}
}
}
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(树状数组)题解

    题意:给你数组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 ...

  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. C#操作sql时注意点

    ①创建必要的索引 ②使用预编译查询 ③使用参数化sql会执行预编译,第一次执行的时候DBMS会为这个SQL语句进行查询优化并执行预编译 ④调整where子句中的连接顺序 ⑤DBMS一般次用自上而下的顺 ...

  2. Android接口回调的理解

    1.各种理解 <1>说白了,就是拿到对象引用,调其方法 <2>实际上就是利用多态的方式调用而已 <3>其实很容易理解的,定义接口,然后提供一个外部的接口设置进去,然 ...

  3. Python数据分析8-----网页文本处理

    1.去除网页的标签,如<br/> from bs4 import BeautifulrSoup preData=BeautifulSoup(data,'html.parser').get_ ...

  4. Extjs获取input值的几种方法

    记录一下: ExtJs获取文本框中值的几种方式 EXTHTML 1.Html文本框 如: 获取值的方式为: var tValue = Ext.getDom('test').value; 或者 var ...

  5. 如何让myeclipse左边选中文件后自动关联右边树

    在左侧项目树的右上角下拉菜单里有link with editor 点击即可

  6. [luogu]P4365[九省联考]秘密袭击coat(非官方正解)

    题目背景 警告:滥用本题评测者将被封号 We could have had it all. . . . . . 我们本该,拥有一切 Counting on a tree. . . . . . 何至于此 ...

  7. Git:与GitHub搭配及SSH登录

    远程库(GitHub)上的地址 搭建本地库 准备一个文件 将地址用别名存在git上 推送到远程库 克隆 克隆的效果 1)完整的把远程库下载到本地 2)别名也完整保留 3)同时也初始化了本地库 邀请团队 ...

  8. LaTeX 图片色偏解决方法

    本系列文章由 @YhL_Leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50327113 在LaTeX的编辑模式中 ...

  9. Nodejs RESTFul架构实践之api篇(转)

    why token based auth? 此段摘自 http://zhuanlan.zhihu.com/FrontendMagazine/19920223 英文原文 http://code.tuts ...

  10. SQL SERVER-主键的建立和删除

    PRIMARY KEY 约束唯一标识数据库表中的每条记录.主键必须包含唯一的值.主键列不能包含 NULL 值.每个表都应该有一个主键,并且每个表只能有一个主键.主键约束操作包含了添加约束和删除约束,修 ...