Pagini recente » Borderou de evaluare (job #103645) | Cod sursa (job #1856147) | Cod sursa (job #2689944) | Arhiva de probleme | Cod sursa (job #1740140)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("datorii.in");
ofstream g("datorii.out");
const int Nmax = 15005;
int n, m, AIB[Nmax];
void Update1(int pos, int x)
{
for(int i = pos; i <= n; i += i&(-i))
{
AIB[i] += x;
}
}
void Update2(int pos, int x)
{
for(int i = pos; i <= n; i += i&(-i))
{
AIB[i] -= x;
}
}
int Suma(int pos)
{
int s = 0;
for(int i = pos; i > 0; i -= i&(-i))
{
s += AIB[i];
}
return s;
}
int main()
{
f>>n>>m;
for(int i = 1; i <= n; i++)
{
int x;
f>>x;
Update1(i,x);
}
while(m--)
{
int x,y,opt;
f>>opt>>x>>y;
if(opt == 0) Update2(x,y);
else
{
g<<Suma(y)-Suma(x-1)<<'\n';
}
}
return 0;
}