Pagini recente » Borderou de evaluare (job #3361122) | Cod sursa (job #3362276) | Cod sursa (job #3364099) | Cod sursa (job #3362273) | Cod sursa (job #3364098)
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream fin ("datorii.in");
ofstream fout ("datorii.out");
struct AIB
{
int sz;
vector<long long> a;
AIB(int N)
{
sz=N;
a.assign(N+2,0);
}
void add(int idx,long long u)
{
for(;idx<=sz;idx+=idx&-idx)a[idx]+=u;
}
long long update(int k)
{
long long sum=0;
for(;k>0;k-=k&-k)sum=sum+a[k];
return sum;
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long N,M;
fin>>N>>M;
vector<long long> v(N+1);
AIB bit(N);
for(int i=1;i<=N;i++)
{
fin>>v[i];
bit.add(i,v[i]);
}
while(M--)
{
int tip;
fin>>tip;
if(tip==0)
{
int V,T;
fin>>V>>T;
bit.add(V,-T);
}
else
{
int l,r;
fin>>l>>r;
fout<<bit.update(r)-bit.update(l-1)<<'\n';
}
}
return 0;
}