Pagini recente » Cod sursa (job #3351131) | Cod sursa (job #3265311) | Cod sursa (job #1413051) | Cod sursa (job #1005927) | Cod sursa (job #3328775)
#include <fstream>
#include <math.h>
using namespace std;
ifstream cin("datorii.in");
ofstream cout("datorii.out");
int v[15001],btg[124];
int main()
{
int n,m,q,n3,y,x,tip,s;
cin>>n>>m;
q=sqrt(n);
for(int n2=0;n2<n;n2++) {
cin>>v[n2];
btg[n2/q]+=v[n2];
}
for(int n2=1;n2<=m;n2++) {
cin>>tip>>y>>x;
y--;
if(tip==0) {
btg[y/q]-=x;
v[y]-=x;
}
if(tip==1) {
s=0;
x--;
while(y%q!=0 && y<=x)
{
s+=v[y];
y++;
}
while(y+q<x)
{
s+=btg[y/q];
y+=q;
}
while(y<=x)
{
s+=v[y];
y++;
}
cout<<s<<'\n';
}
}
return 0;
}