algorithm_2024/src/P3374/P3374.cpp
2024-11-16 15:48:29 +08:00

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';
}
}
}