博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
树状数组
阅读量:4612 次
发布时间:2019-06-09

本文共 1590 字,大约阅读时间需要 5 分钟。

模板如下:

int lowb(int t){    return t & (-t);}void add(int i,int v){    for( ;i < n;ar[i] += v,i += lowb(i));    return ;}int sum(int i){    int s = 0;    for(;i > 0;s += ar[i],i -= lowb(i));    return s;}

例题: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, each book has its knowledge a[i]a[i]a[i].

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

That means, if he reads books from lll to rrr, he will get a[l]×L+a[l+1]×(L−1)+⋯+a[r−1]×2+a[r]a[l] \times L + a[l+1] \times (L-1) + \cdots + a[r-1] \times 2 + a[r]a[l]×L+a[l+1]×(L−1)+⋯+a[r−1]×2+a[r] (LLL is the length of [ lll, rrr ] that equals to r−l+1r - l + 1r−l+1).

Now Ryuji has qqq questions, you should answer him:

111. If the question type is 111, you should answer how much knowledge he will get after he reads books [ lll, rrr ].

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

Input

First line contains two integers nnn and qqq (nnn, q≤100000q \le 100000q≤100000).

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

Then in next qqq line each line contains three integers aaa, bbb, ccc, if a=1a = 1a=1, it means question type is 111, and bbb, ccc represents [ lll , rrr ]. if a=2a = 2a=2 , it means question type is 222 , and bbb, ccc means Ryuji changes the bth book' knowledge to ccc

Output

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

样例输入

5 31 2 3 4 51 1 32 5 01 4 5

样例输出

108

 

转载于:https://www.cnblogs.com/lu1nacy/p/10016632.html

你可能感兴趣的文章
vue+element-ui实现表格checkbox单选
查看>>
linux公司常用基础命令必知必会
查看>>
Oracle——PL/SQL 语句
查看>>
java nio
查看>>
Spring框架的AOP的底层实现之JDK的动态代理(代码了解,理解原理)
查看>>
查询和修改selinux状态
查看>>
hdu 1348:Wall(计算几何,求凸包周长)
查看>>
手动下载spring jar包
查看>>
WinForm登陆窗体,基础属性
查看>>
Android进阶篇-WindowManager
查看>>
外卖APP调研
查看>>
java-泛型
查看>>
网站优化
查看>>
Java高级特性 第5节 序列化和、反射机制
查看>>
gcc 头文件依赖关系 分析工具
查看>>
每天敲一点code
查看>>
jquery
查看>>
IntelliJ IDEA 中文乱码问题解决办法
查看>>
【文文殿下】网络流24题计划
查看>>
各大搜索引擎智能提示API(JSONP跨域实现自动补全搜索建议)
查看>>