51 lines
945 B
C++
51 lines
945 B
C++
#include <cstdint>
|
|
#include <iostream>
|
|
#include <istream>
|
|
|
|
using ll = int64_t;
|
|
using std::cin, std::cout;
|
|
|
|
const ll maxn = 5e5+5;
|
|
ll n, m, bit[maxn];
|
|
|
|
ll lb(const ll &n){
|
|
return n&(-n);
|
|
}
|
|
|
|
int main(){
|
|
std::iostream::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
|
|
|
|
cin>>n>>m;
|
|
for(ll i{1};i<=n;i++){
|
|
ll a;
|
|
cin>>a;
|
|
ll now{i};
|
|
while(now<=n){
|
|
bit[now]+=a;
|
|
now+=lb(now);
|
|
}
|
|
}
|
|
const auto sch = [](ll n)->ll{
|
|
ll res{};
|
|
while(n!=0){
|
|
res+=bit[n];
|
|
n-=lb(n);
|
|
}
|
|
return res;
|
|
};
|
|
// for(ll i{1};i<=n;i++){
|
|
// cout<<sch(i)-sch(i-1)<<'\n';
|
|
// }
|
|
while(m--){
|
|
ll t, x, y;
|
|
cin>>t>>x>>y;
|
|
if(t==1){
|
|
while(x<=n){
|
|
bit[x]+=y;
|
|
x+=lb(x);
|
|
}
|
|
}else{
|
|
cout<<sch(y)-sch(x-1)<<'\n';
|
|
}
|
|
}
|
|
} |