Cod sursa(job #1211993)

Utilizator vasica38Vasile Catana vasica38 Data 23 iulie 2014 16:53:14
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include<fstream>
using namespace std;
int a[15002] ,i,j,k,m,n,u,x,y;
ifstream cin("datorii.in");
ofstream cout("datorii.out");

void update(int poz, int u)
{
     while (poz<=n)
           {
           a[poz]-=u;
           poz+=(poz&(-poz));
           }
}
int suma(int poz)
{
    int sol=0;
    while (poz>=1) 
          {
          sol+=a[poz];
          poz-=(poz&(-poz));
          }
    return sol;
}

int main()
{   
    cin>>n>>m;
    for (i=1; i<=n ; ++i){
              cin>>x;
              update(i,-x);
                          }
    
    
    for (i=1; i<=m ; i++)
        {
              cin>>k;
              if (k==0) {
                        cin>>x>>y;
                        update(x,y);
                        }
              if (k==1) {
                        cin>>x>>y;
                        cout<<suma(y)-suma(x-1)<<"\n";
                        }
        }
cin.close();
cout.close();
return 0;
}