Pagini recente » Cod sursa (job #2657733) | Cod sursa (job #2630790) | Cod sursa (job #2853673) | Cod sursa (job #2513299) | Cod sursa (job #2316465)
#include <fstream>
#define zeros(x) ((x^(x-1))&x)
using namespace std;
ifstream in("datorii.in");
ofstream out("datorii.out");
int aib[15001];
int n,m;
void add (int poz, int x)
{
for (int i = poz; i < n; i += zeros(i))
{
aib[i] += x;
}
}
int compute (int poz)
{
int ans = 0;
for (int i = poz; i > 0; i -= zeros(i))
{
ans += aib[i];
}
return ans;
}
int main()
{
int i,a,x,y,ans;
in>>n>>m;
n++;
for (i = 1; i < n; i++)
{
in >> x;
add (i, x);
}
for (i = 0; i < m; i++)
{
in >>a>> x >> y;
if (a==0)
{
add (x, -y);
}
else
{
ans = compute (y) - compute(x - 1);
out << ans << '\n';
}
}
return 0;
}