Pagini recente » Cod sursa (job #1641982) | Cod sursa (job #94515) | Cod sursa (job #3277214) | Cod sursa (job #1148779) | Cod sursa (job #3153354)
#include <iostream>
#include <fstream>
using namespace std;
long long n,m,x,v[263002],p=1;
void update(int poz,int x)
{
poz=poz+p-1;
v[poz]=x;
while (poz!=1)
{
poz/=2;
v[poz]=v[poz*2]+v[poz*2+1];
}
}
long long suma(int a,int b,int st,int dr,int index)
{
if (a<=st && b>=dr)
return v[index];
if (dr<a || st>b)
return 0;
return 1LL*(suma(a,b,st,(st+dr)/2,index*2)+suma(a,b,(st+dr)/2+1,dr,index*2+1));
}
int main()
{
ifstream f ("datorii.in");
ofstream g ("datorii.out");
f>>n>>m;
int a,b,c;
while (p<n)
p*=2;
int q[15005];
for (int i=1; i<=n; i++)
{
f>>q[i];
update(i,q[i]);
}
n=p;
for (int i=1; i<=m; i++)
{
f>>c>>a>>b;
if (c==1)
g<<suma(a,b,1,n,1)<<'\n';
else
update(a,q[a]-b);
}
}