Pagini recente » Istoria paginii utilizator/maleticimiroslav | Cod sursa (job #1139468) | Istoria paginii utilizator/emilianmanescu | Cod sursa (job #2829834) | Cod sursa (job #1900720)
#include <fstream>
using namespace std;
ifstream fin("datorii.in");
ofstream fout("datorii.out");
#define nmax 15001
#define zeros(x) ((x^(x-1))&x)
int n, arb[nmax];
void update(int poz, int x)
{
int i;
for(i=poz; i<=n; i+=zeros(i))
arb[i]+=x;
}
int calc(int poz)
{
int s=0, i;
for(i=poz; i>0; i-=zeros(i))
s+=arb[i];
return s;
}
int main()
{
int m, i, op, x, y;
fin>>n>>m;
for(i=1; i<=n; i++)
{
fin>>x;
update(i, x);
}
for(i=1; i<=m; i++)
{
fin>>op>>x>>y;
if(op==0)
update(x, -y);
else
fout<<calc(y)-calc(x-1)<<'\n';
}
return 0;
}