Pagini recente » Cod sursa (job #57501) | Cod sursa (job #2676011) | Cod sursa (job #1603148) | Cod sursa (job #479285) | Cod sursa (job #2071222)
#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)
{
int cnt = 0;
while (pozitie <= n)
{
cnt ++;
aib[pozitie]+=cantitate;
assert (0 <= aib[pozitie]);
pozitie += zeros(pozitie);
assert (cnt <= 20);
}
}
int compute1(int pozitie2)
{
int cnt = 0;
int rez=0;
while (pozitie2)
{
rez+=aib[pozitie2];
assert (0 <= aib[pozitie2]);
pozitie2 -= zeros(pozitie2);
cnt ++;
assert (cnt <= 20);
}
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;
assert (1 <= n && n <= 15000);
assert (1 <= m && m <= 100000);
for(i=1;i<=n;i++)
{
fin>>x;
assert (0 <= x && x <= 1000);
add(i,x);
}
for(i=1;i<=m;i++)
{
fin>>x>>y>>z;
assert (x == 0 || x == 1);
if(x==0)
{
assert (1 <= y && y <= n);
assert (0 <= z && z <= 1000);
add(y,-z);
}
if(x==1)
{
fout<<compute(y,z)<<endl;
assert (1 <= y && y <= z && z <= n);
}
}
}