Pagini recente » Cod sursa (job #3133695) | Cod sursa (job #167987) | Cod sursa (job #303784) | Cod sursa (job #1133943) | Cod sursa (job #2071214)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int aib[15005],n;
int zeros (int x)
{
return x & (-x);
}
void add(int pozitie, int cantitate)
{
while (pozitie <= n)
{
aib[pozitie]+=cantitate;
pozitie += zeros(pozitie);
}
}
int compute1(int pozitie2)
{
int rez=0;
while (pozitie2)
{
rez+=aib[pozitie2];
pozitie2 -= zeros(pozitie2);
}
return rez;
}
int compute (int poz1, int poz2)
{
return compute1(poz2) - compute1(poz1 - 1);
}
int main()
{
// return 0;
int m,i,x,y,z,j;
fin>>n>>m;
for(i=1;i<=n;i++)
{
fin>>x;
add(i,x);
}
for(i=1;i<=m;i++)
{
fin>>x>>y>>z;
if(x==0)
{
add(y,-z);
}
if(x==1)
{
fout<<compute(y,z)<<endl;
}
}
}