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. java/javascript 时间操作工具类

    一.java 时间操作工具类 import org.springframework.util.StringUtils; import java.text.ParseException; import ...

  2. 「JavaSE 重新出发」05.01.01 equals 方法

    equals 方法示例 // 代码来自<Java核心技术 卷I>P167 // 父类 public class Employee{ ... public boolean equals(Ob ...

  3. vue中slot的用法案例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Spring、Spring MVC、MyBatis 整合文件配置详解

    使用SSM框架做了几个小项目了,感觉还不错是时候总结一下了.先总结一下SSM整合的文件配置.其实具体的用法最好还是看官方文档. Spring:http://spring.io/docs MyBatis ...

  5. 使用其他Java工程导入hadoop源码用于在hadoop工程中查看源码

    疑问:在开发hadoop程序的时候,有时候需要查看hadoop的源码,但是开发环境看不到,甚是烦恼,经过网上搜索和琢磨,终于实现了,虽然有点绕,但是目的达到了. 第一步:下载hadoop的源码包:ha ...

  6. 字典树Trie Tree

    又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种.典型应用是用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计.它的优点是:利用字符串的公共前缀 ...

  7. vue 动态拼接地址,使用本地的图片不显示

    <el-col :span="4" v-for="(item, index) in listData" :key="index"> ...

  8. Laravel核心解读--Contracts契约

    Contracts Laravel 的契约是一组定义框架提供的核心服务的接口, 例如我们在介绍用户认证的章节中到的用户看守器契约IllumninateContractsAuthGuard 和用户提供器 ...

  9. Python基本类型操作

    # str = "2017.1.1.wmv" # #print(str[str.rfind('.'):]) # #print(str.count(".")) # ...

  10. 前端实现input[type='file']上传图片预览效果

    众所周知JavaScript在设计上处于安全角度考虑,是不允许读写本地文件的(原因请自行百度): 但是在实际项目应用中,经常会使用到上传图片,并且可以让用户直接预览图片.对于此种做法有两种方法可以实现 ...