Pagini recente » Cod sursa (job #3264440) | Cod sursa (job #154832) | Cod sursa (job #1319569) | Cod sursa (job #1764147) | Cod sursa (job #3206853)
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;
const string fn("datorii");
ifstream in(fn + ".in");
ofstream out(fn + ".out");
#define cin in
#define cout out
int n,q;
struct FenwickTree{
vector<ll> aib;
int n;
void init(int _n)
{
n=_n;
aib.resize(n+5,0);
}
void upd(int pos,int val)
{
for(;pos<=n;pos+=pos&-pos)
aib[pos]+=val;
}
ll query(int pos)
{
ll sum=0;
for(;pos>0;pos-=pos&-pos)
sum+=aib[pos];
return sum;
}
}aib;
int main()
{
int n,q;
cin>>n>>q;
aib.init(n);
for(int i=1,x;i<=n;i++)
cin>>x,aib.upd(i,x);
while(q--)
{
int t,l,r;
cin>>t>>l>>r;
if(t==0)
{
aib.upd(l,-r);
}
else
{
cout<<aib.query(r)-aib.query(l-1)<<'\n';
}
}
return 0;
}