Cod sursa(job #1146372)

Utilizator a96tudorAvram Tudor a96tudor Data 18 martie 2014 21:56:05
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include<cstdio>
#define ub(x) (x&(-x))
#define lung unsigned long long
using namespace std;
lung AIB[20000],x,X,Y,k,S,N,M;
inline lung Qwerry(lung x)
{
    lung S=0;
    for (int i=x;i>0;i-=ub(i)) S+=AIB[i];
    return S;
}
inline void Update(lung x,lung NR)
{
    for (int i=x;i<=N;i+=ub(i)) AIB[i]+=NR;
}
int main()
{
    freopen("datorii.in","r",stdin);
    freopen("datorii.out","w",stdout);
    scanf("%d%d",&N,&M);
    for (int i=1;i<=N;++i) scanf("%lld",&x), Update(i,x);
    for (int i=1;i<=M;++i)
    {
        scanf("%lld%lld%lld",&k,&X,&Y);
        if (k==0) Update(X,-Y);
            else
                {
                    S=Qwerry(Y)-Qwerry(X-1);
                    printf("%d\n",S);
                }
    }
    fclose(stdin); fclose(stdout);
    return 0;
}