Cod sursa(job #1505355)

Utilizator Vlad_317Vlad Panait Vlad_317 Data 19 octombrie 2015 01:06:00
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 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)
{
    int s=0;
    while(poz>0)
    {
        s+=aib[poz];
        poz-=ub(poz);
    }
    return s;
}

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++)
    {
        int 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;
}