Pagini recente » Cod sursa (job #1711283) | Cod sursa (job #1872669) | Cod sursa (job #1751421) | Cod sursa (job #1227048) | Cod sursa (job #2790085)
#include <bits/stdc++.h>
using namespace std;
int N, M, a, b, zero, p;
bool quest;
vector<int> vect;
void update(int poz, int val)
{
poz += zero;
vect[poz] -= val;
for(int i=poz/2; i>0; i/=2)
vect[i] -= val;
}
int suma(int nod, int A, int B)
{
if(a <= A && B <= b)
return vect[nod];
if(a > B || A > b)
return 0;
int mij = (A+B)/2;
return suma(2*nod, A, mij) + suma(2*nod+1, mij+1, B);
}
int main()
{
ifstream fin("datorii.in");
ofstream fout("datorii.out");
fin>>N>>M;
p = 1;
while(p<=N)
p*=2;
zero = p - 1;
vect = vector<int>(2*p, 0);
for(int i=1; i<=N; i++)
fin>>vect[zero+i];
for(int i=zero; i>=1; i--)
vect[i] = vect[2*i] + vect[2*i+1];
for( ; M; M--)
{
fin>>quest>>a>>b;
if(quest == false )
update(a, b);
else
{
fout<<suma(1, 1, p)<<endl;
}
}
return 0;
}