Cod sursa(job #14322)

Utilizator pitradaPit-Rada Ionel-Vasile pitrada Data 8 februarie 2007 19:02:31
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include<fstream>
using namespace std;
fstream f,g;

long A[15001],B[15001],N,M,i,j,x,y,z,s,ok;
int main()
{
f.open("datorii.in",ios::in);
g.open("datorii.out",ios::out);

f>>N>>M;
B[0]=0;
for (i=1;i<=N;i++)
  {
  f>>A[i];
  B[i]=B[i-1]+A[i];
  }
ok=1;
for (i=1;i<=M;i++)
  {
  f>>x>>y>>z;
  if (x==0) 
     {
     A[y]-=z;
     ok=0;
     }
     else
     {
     if (ok==0)
       {
       for (j=1;j<=N;j++) B[j]=B[j-1]+A[j];     
       ok=1;
       }
     g<<B[z]-B[y-1]<<endl;
     }
  }


g.close();
f.close();
return 0;
}