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
(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 11, you should answer how much knowledge he will get after he reads books [ ll, rr ].
2. If the question type is 22, Ryuji will change the ith book's knowledge to a new value.
First line contains two integers n and .
The next line contains n integers represent .
Then in next qq line each line contains three integers aa, bb, cc, if a = 1a=1, it means question type is 11, and bb, cc represents [ l , r ]. if a = 2a=2 , it means question type is 22 , and bb, cc means Ryuji changes the bth book' knowledge to cc
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]和i*a[i]就好了,这里用的是树状数组
#include
using namespace std;
typedef long long ll;
ll a[100005],b[100005],
n,q;
void add(ll a[],int x,ll val)
{
while(x<=n)
{
a[x]+=val;
x += x&-x;
}
}
ll query(ll a[],int x)
{
ll ans = 0;
while(x)
{
ans += a[x];
x -= x&-x;
}
return ans;
}
int main()
{
ll t,l,r;
scanf("%d%d",&n,&q);
for(int i=0;i