Pagini recente » Cod sursa (job #3326983) | Cod sursa (job #278396) | Cod sursa (job #3345825) | Cod sursa (job #2132220) | Cod sursa (job #3328675)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
int v[15005];
int b[130];
int main()
{
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int n,m;
fin>>n>>m;
int BSZ=sqrt(n);
for(int i=0;i<n;i++)
{
fin>>v[i];
b[i/BSZ]+=v[i];
}
for(int i=1;i<=m;i++)
{
int t,x,y;
fin>>t>>x>>y;
if(t==0)
{
x--;
v[x]-=y;
b[x/BSZ]-=y;
}
else
{
int s=0;
int j=x-1;
while(j%BSZ!=0 && j<y)
{
s+=v[j];
j++;
}
while(j+BSZ<y)
{
s+=b[j/BSZ];
j+=BSZ;
}
while(j<y)
{
s+=v[j];
j++;
}
fout<<s<<'\n';
}
}
fin.close();
fout.close();
return 0;
}