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# 3.0的新特性

    自动属性. 之前定义属性的步骤: private filed + public property. 现在的形式:int id{get;set;}. 可以分别设置get/set的保护级别(protect ...

  2. CentOS 5/6 下添加epel源

    如果既想获得 RHEL 的高质量.高性能.高可靠性,又需要方便易用(关键是免费)的软件包更新功能,那么 Fedora Project 推出的 EPEL(Extra Packages for Enter ...

  3. css pointer-event

    详见:张鑫旭 CSS3 pointer-events:none应用举例及扩展 pointer-events:none ,可以使事件穿透, 如: 2 覆盖在 1 上面. 给 2 设置 pointer-e ...

  4. 在centos6.5上升级php-libxml版本到2.9.0

    当前系统,软件版本说明: php libxml glibc 2.12 zlib xz-libs 需求: 应开发的需求,线上环境,php-libxml版本升级到2.8以上. 升级步骤:1.安装工具集 y ...

  5. Python 进行网络编程

    Date: 2019-06-10 Author: Sun 1. Python TCP通信实现 socket()函数 Python 中,我们用 socket()函数来创建套接字,语法格式如下: sock ...

  6. D. Destruction of a Tree_dfs序_性质分析_思维题

    题意: 给定一棵树,每次可以拆掉一个树上度数为偶数的点,拆掉该点后,与该点所连的所有边都会被删掉.问,是否有一种删点顺序可以删掉所有的点.如果有,则输出任意一组解. 数据范围:线性做法 O(n)O(n ...

  7. 【XSY3306】alpha - 线段树+分治NTT

    题目来源:noi2019模拟测试赛(一) 题意: 题解: 这场三道神仙概率期望题……orzzzy 这题暴力$O(n^2)$有30分,但貌似比正解更难想……(其实正解挺好想的) 注意到一次操作实际上就是 ...

  8. Flask-Babel 使用简介(翻译文档)

    最近用flask-bable翻译一个项目,在网站上查找到有一个示例文档,地址:http://translations.readthedocs.io/en/latest/flask-babel.html ...

  9. Java String 字符串截取和获取文件的上级目录

    public String test() { String root = ServletActionContext.getServletContext().getRealPath("/&qu ...

  10. unity 获取UGUI中的Text字的坐标

    using System.Collections; using UnityEngine; using UnityEngine.UI; public class TextMoveHelper : Mon ...