Pagini recente » Cod sursa (job #161570) | Cod sursa (job #1750443) | Cod sursa (job #1819896) | Cod sursa (job #808359) | Cod sursa (job #1852287)
#include <iostream>
#include <fstream>
#define zeros(x) ( (x ^ (x - 1)) & x )
using namespace std;
int n, m, aib[15005], quantity, st, dr, element;
void Add(int x, int quantity)
{
for(int i = x; i <= n; i += zeros(i))
aib[i] += quantity;
}
void Remove(int x, int quantity)
{
for(int i = x; i <= n; i += zeros(i))
aib[i] -= quantity;
}
int Compute(int x)
{
int sum = 0;
for(int i = x; i >= 1; i -= zeros(i))
sum += aib[i];
return sum;
}
void AIB()
{
ifstream fin("datorii.in");
ofstream fout("datorii.out");
fin >> n >> m;
for(int i = 1; i <= n; ++i){
fin >> element;
Add(i, element);
}
int type, poz;
for(int i = 1; i <= m; ++i){
fin >> type;
if(type == 0) {
fin >> poz >> quantity;
Remove(poz, quantity);
}
if(type == 1){
fin >> st >> dr;
fout << Compute(dr) - Compute(st - 1) << '\n';
}
}
}
int main()
{
AIB();
return 0;
}