• 262144K
 

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i].

Unfortunately, the longer he learns, the fewer he gets.

That means, if he reads books from ll to rr, he will get 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).

Now Ryuji has qq questions, you should answer him:

1. If the question type is 1, you should answer how much knowledge he will get after he reads books [ l, r ].

2. If the question type is 2, Ryuji will change the ith book's knowledge to a new value.

Input

First line contains two integers nn and qq (n, q≤100000).

The next line contains n integers represent a[i](a[i]≤1e9) .

Then in next qq line each line contains three integers a, b, c, if a = 1, it means question type is 1, and b, ccrepresents [ l, r ]. if a =2 , it means question type is 2 , and bb, cc means Ryuji changes the bth book' knowledge to cc

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

题目来源

ACM-ICPC 2018 徐州赛区网络预赛

 #define  ull unsigned  long  long
#define ll long long
#define N 100009
#define lowbit(x) x&(-x)
ull c1[N],c2[N];
int n,q;
void update1(int x,ull num)
{
while(x<=n)
{
c1[x]+=num;
x+=lowbit(x);
}
}
ull getsum1(int x)
{
ull sum=;
while(x>)
{
sum+=c1[x];
x-=lowbit(x);
}
return sum;
}
void update2(int x,ull num)
{
while(x<=n)
{
c2[x]+=num;
x+=lowbit(x);
}
}
ull getsum2(int x)
{
ull sum=;
while(x>)
{
sum+=c2[x];
x-=lowbit(x);
}
return sum;
}
int main()
{
scanf("%d%d",&n,&q);
ull x;
for(int i=;i<=n;i++)
{
scanf("%lld",&x);
update1(i,x);
update2(i,1ull*(n-i+)*x);//在前面加个 ull 保证整体是ull 的
}
int op,l,r;
while(q--)
{
scanf("%d%d%d",&op,&l,&r);
if(op==)
{
ull ans1=1ull*(n-r)*(getsum1(r)-getsum1(l-));
ull ans2=getsum2(r)-getsum2(l-);
printf("%lld\n",ans2-ans1);//"u" 是unsigned int
}
else{
ull temp=getsum1(l)-getsum1(l-);
update1(l,1ull*(r-temp) );
update2(l,1ull*(r-temp)*(n-l+)) ;
}
}
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 (线段树)

    Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, ea ...

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

  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 徐州赛区网络预赛 B(dp || 博弈(未完成)

    传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...

  7. ACM-ICPC 2018 徐州赛区网络预赛 D 杜教筛 前缀和

    链接 https://nanti.jisuanke.com/t/31456 参考题解  https://blog.csdn.net/ftx456789/article/details/82590044 ...

  8. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)

    ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...

随机推荐

  1. AtCoder Regular Contest 075 2017年6月4日 C、D、E题解

    http://arc075.contest.atcoder.jp/assignments 昨晚做的atcoder,今天写个简单题解. F题不会做,800point的,就跪了,要等zk大佬来做.zk能做 ...

  2. 远程调试工具weinre使用教程

    一:前言 我们都知道,chrome的开发者工具(f12)是一个方便我们调试PC页面的工具.但是现在我们的开发离不开移动端,那如果我们需要对手机页面进行调试,那该怎么办了? 当然,chrome的开发者工 ...

  3. 【迷你微信】基于MINA、Hibernate、Spring、Protobuf的即时聊天系统:2.技术简介之MinaFilter(1)

    欢迎阅读我的开源项目<迷你微信>服务器与<迷你微信>客户端 Filter filter:过滤器?(不知道是不是这么翻译,算了知道意思就好了╮(╯▽╰)╭),这种东西在很多语言中 ...

  4. 配置文件无法修改(以修改my-default.ini为例)

    现象: 保存my-default.ini时如果提示“拒绝访问”,右击my-default.ini文件 解决办法: 属性—>安全—>修改权限

  5. userBean-作用范围application

    package com.java1234.model; public class Student { private String name;private int age; public Strin ...

  6. OSSIM安装与使用感受

    下载地址 http://www.alienvault.com OSSIM通过将开源产品进行集成,从而提供一种能够实现安全监控功能的基础平台.它的目标是提供一种集中式.有组织的,能够更好地进行监测和显示 ...

  7. Python:numpy数组转换为json格式

    在python中,如何将一个numpy数组转换为json格式? 这是最近遇到的一个问题,做个笔记. 假设arr为numpy数组,将其转换为json格式: 总体思想是①首先转换为python的list, ...

  8. Spark Job具体的物理执行

    即使采用pipeline的方式,函数f对依赖的RDD中的数据集合的操作也会有两种方式: 1.f(record),f作用于集合的每一条记录,每次只作用于一条记录 2.f(records),f一次性作用于 ...

  9. tpcc-mysql 实践

    一.TPCC 介绍 TPC:全称Transaction Processing Performance Council (事务处理性能委员会),是一家非盈利性组织,该组织制定各种商业应用的基准测试规范, ...

  10. 通用的flash代码

    黑体字部分为常修改的部分 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase=&quo ...