Pagini recente » Cod sursa (job #3328680) | Cod sursa (job #1290884) | Cod sursa (job #512943) | Cod sursa (job #2456643) | Cod sursa (job #3328664)
#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=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;
x--;
//y--;
if(t==0)
{
v[x]-=min(y,v[x]);
b[y/BSZ]-=min(y,v[x]);
}
else
{
int s=0;
y--;
while(x%BSZ!=0 && x<=y)
{
s+=v[x];
x++;
}
///int k=j/BSZ;
while(x+BSZ<y)
{
s+=b[x];
x+=BSZ;
///k++;
}
while(x<=y)
{
s+=v[x];
x++;
}
fout<<s<<'\n';
}
}
fin.close();
fout.close();
return 0;
}