Cod sursa(job #1132666)

Utilizator stoicatheodorStt sas stoicatheodor Data 3 martie 2014 19:46:33
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
using namespace std;

ifstream f("datorii.in");
ofstream g("datorii.out");

int a[15005],n,m;

int s(int x)
{
    int s(0);
    while (x)
	{
        s=s+a[x];
        x-=x&-x;
    }

    return s;
}

void achitare(int x, int val)
{
    while (x<=n)
	{
        a[x]=a[x]+val;
        x+=x&-x;
    }
}
int main()
{
    int q,x,y;
    int i;

    f>>n>>m;
    for(i=1;i<=n;i++)
	{
        f>>x;
        achitare(i,x);
    }

    while (m--)
	{

        f>>q>>x>>y;
        if (q==0)
            achitare(x,-y);
        else
            g<<s(y)-s(x-1)<<"\n";
    }

    f.close();
    g.close();

    return 0;
}