Pagini recente » Cod sursa (job #641132) | Cod sursa (job #2006596) | Cod sursa (job #1796555) | Cod sursa (job #1061679) | Cod sursa (job #2355350)
#include <fstream>
using namespace std;
ifstream f("datorii.in");
ofstream g("datorii.out");
struct datorie
{
int zi,val;
};
datorie s1[15005];
int n,m,i,j;
int x,s[15005],k;
int tip,v,t,p,q,suma;
int main()
{
f>>n>>m;
for (i=1;i<=n;i++)
{
f>>x;
s[i]=s[i-1]+x;
}
for (i=1;i<=m;i++)
{
f>>tip;
if (tip==0)
{
f>>t>>v;
k++;
s1[k].val=v;
s1[k].zi=t;
}
else
{
f>>p>>q;
suma=s[q]-s[p-1];
for (j=1;j<=k;j++)
if (s1[j].zi>=p && s1[j].zi<=q)
suma-=s1[j].val;
g<<suma<<"\n";
}
}
return 0;
}