Pagini recente » Cod sursa (job #2272830) | Cod sursa (job #1677591) | Cod sursa (job #1366295) | Cod sursa (job #527718) | Cod sursa (job #651566)
Cod sursa(job #651566)
#include <fstream>
#define function(x) ((x) & (-x))
using namespace std;
ifstream in("datorii.in");
ofstream out("datorii.out");
int s[15001];
int n ,m , command, firstValue, secondValue;
void addAndRemove(int position, int value)
{
for(int i = position; i <= n; i+= function(i))
{
s[i] += value;
}
}
void citire()
{
in>>n>>m;
int a;
for(int i = 1; i <= n; i++)
{
in>>a;
addAndRemove(i, a);
}
}
int getSume(int a)
{
int sume = 0;
for(int i = a; i >= 1; i-= function(i))
{
sume += s[i];
}
return sume;
}
void resolve()
{
for(int i = 1; i <= m; i++)
{
in>>command>>firstValue>>secondValue;
if(command)
{
int a = getSume(secondValue);
int b = getSume(firstValue - 1);
out<<a - b<<'\n';
}
else
{
addAndRemove(firstValue, -secondValue);
}
}
}
int main()
{
citire();
resolve();
}