Cod sursa(job #1415108)

Utilizator vasica38Vasile Catana vasica38 Data 3 aprilie 2015 19:38:21
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include<fstream>
using namespace std;

int a[15001],i,j,k,m,n,u,x,y;


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()
{
    ifstream cin("datorii.in");
    ofstream cout("datorii.out");
    cin>>n>>m;
    for (i=1; i<=n; ++i)
    {
        cin>>x;
        update(i,-x);

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