Cod sursa(job #1505354)

Utilizator Vlad_317Vlad Panait Vlad_317 Data 19 octombrie 2015 00:58:53
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <stdio.h>

using namespace std;

const int MAX=150000;

int aib[MAX+1],n;

int ub(int x){
  return x & (-x);
}

void update(int poz, int val)
{
    if(poz>n)
        return;
    aib[poz]+=val;
    poz+=ub(poz);
    update(poz,val);
}

int querry(int poz)
{
    if(poz<1)
        return 0;
    return aib[poz] + querry(poz-ub(poz));
}

int main()
{
    freopen("datorii.in","r",stdin);
    freopen("datorii.out","w",stdout);

    int m;

    scanf("%d%d",&n,&m);

    for(int i=1;i<=n;i++)
    {
        int val;
        scanf("%d",&val);
        update(i,val);
    }

    for(int i=1;i<=m;i++)
    {
        bool op;
        int x,y;
        scanf("%d%d%d",&op,&x,&y);
        if( op==0 )
            update(x,-y);
        else
            printf("%d\n",querry(y)-querry(x-1));

    }

    return 0;
}