Pagini recente » Cod sursa (job #3339890) | Cod sursa (job #1869953) | Cod sursa (job #3338644) | Cod sursa (job #521519) | Cod sursa (job #3328654)
#include <iostream>
#include <fstream>
using namespace std;
int v[15005];
const int BSZ=123;
int b[BSZ+5];
int main()
{
ifstream fin("datorii.in");
ofstream fout("datorii.out");
int n,m;
fin>>n>>m;
for(int i=1;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)
{
v[x]-=min(y,v[x]);
b[y/BSZ]-=min(y,v[x]);
}
else
{
int s=0;
int j;
int limit=x/BSZ+1;
for(j=x;j<limit*BSZ && j<=y;j++)
{
s+=v[j];
}
while(j+BSZ<=y)
{
s+=b[j/BSZ];
j+=BSZ;
}
while(j<=y)
{
s+=v[j];
}
fout<<s<<'\n';
}
}
fin.close();
fout.close();
return 0;
}