70 lines
1.3 KiB
C++
70 lines
1.3 KiB
C++
|
#include<bits/stdc++.h>
|
||
|
using namespace std;
|
||
|
#define int long long
|
||
|
|
||
|
int lowbit(int x);
|
||
|
void update(int i,int n,int num,vector<int> &a);
|
||
|
int query(int i,vector<int> &a);
|
||
|
int rangeQuery(int l,int r,vector<int> &a);
|
||
|
int readint();
|
||
|
|
||
|
signed main(){
|
||
|
int n=readint(),m=readint();
|
||
|
vector<int> a(n+1,0);
|
||
|
for(int i=1;i<=n;i++){
|
||
|
int num;
|
||
|
cin>>num;
|
||
|
update(i, n, num, a);
|
||
|
}
|
||
|
for(int i=1;i<=m;i++){
|
||
|
const int o = readint();
|
||
|
if(o==1){
|
||
|
const int x=readint(),k=readint();
|
||
|
update(x, n, k, a);
|
||
|
}else{
|
||
|
const int x=readint(),y=readint();
|
||
|
cout<<rangeQuery(x, y, a)<<endl;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
int readint(){
|
||
|
int x=0,w=1;
|
||
|
char ch=0;
|
||
|
while(!isdigit(ch)){
|
||
|
if(ch=='-')w=-1;
|
||
|
ch=getchar();
|
||
|
}
|
||
|
while(isdigit(ch)){
|
||
|
x=x*10+(ch-'0');
|
||
|
ch=getchar();
|
||
|
}
|
||
|
return x*w;
|
||
|
}
|
||
|
|
||
|
|
||
|
int rangeQuery(int l,int r,vector<int> &a){
|
||
|
return query(r, a) - query(l-1, a);
|
||
|
}
|
||
|
|
||
|
int query(int i,vector<int> &a){
|
||
|
int sum=0;
|
||
|
while(i>0){
|
||
|
sum+=a[i];
|
||
|
i-=lowbit(i);
|
||
|
}
|
||
|
return sum;
|
||
|
}
|
||
|
|
||
|
void update(int i,int n,int num,vector<int> &a){
|
||
|
while(i<=n){
|
||
|
a[i]+=num;
|
||
|
i+=lowbit(i);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int lowbit(int x){
|
||
|
return x&(-x);
|
||
|
}
|