Pagini recente » Cod sursa (job #1833298) | Cod sursa (job #2874434) | Cod sursa (job #2646901) | Cod sursa (job #346999) | Cod sursa (job #3177275)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
const int Nmax=15001;
long long aib[Nmax]; int n;
int p2min(int x)
{
return (x&(-x));
}
void addAIB(int pos, int x)
{
while(pos<=n)
{
aib[pos]+=x;
pos+=p2min(pos);
}
}
long long getsumAIB(int pos)
{
long long rez=0;
while(pos>0)
{
rez+=aib[pos];
pos-=p2min(pos);
}
return rez;
}
int main()
{
int m,x;
fin>>n>>m;
for(int i=1; i<=n; i++)
{
fin>>x;
addAIB(i, x);
}
for(int i=1; i<=m; i++)
{
int t,a,b;
fin>>t>>a>>b;
if(t==0)
{
addAIB(a, -b);
}
else
{
fout<<getsumAIB(b)-getsumAIB(a-1)<<'\n';
}
}
return 0;
}