Cod sursa(job #1147597)

Utilizator addy01adrian dumitrache addy01 Data 19 martie 2014 23:04:10
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.42 kb
#include <cstdio>
#include <cctype>
using namespace std;

const int BUFF_SIZE = 4096;
char Buffer[BUFF_SIZE];
int pos = BUFF_SIZE;

inline char getChar ()
{
    if (pos == BUFF_SIZE){
        fread (Buffer, 1, BUFF_SIZE, stdin);
        pos = 0;
    }

    return Buffer[pos ++];
}

inline int getInt ()
{
    int x = 0;
    char c;

    do{
        c = getChar ();
    } while (!isdigit (c));

    do{
        x = x * 10 + c - '0';
        c = getChar ();
    } while (isdigit (c));

    return x;
}


const int maxn = 15001;
int n,m;
int AIB[maxn];
inline int lsb(int x)
{
    return x&(-x);
}

void Update(int poz,int val)
{
    for( ; poz <= n; poz +=lsb(poz) )
        AIB[poz]-=val;
}

int Query(int poz)
{
    int Ans=0;
    for( ; poz >= 1 ; poz -= lsb(poz) )
        Ans+=AIB[poz];

    return Ans;

}

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

    n=getInt();
    m=getInt();
    int i,x,y;
    for(i=1;i<=n;i++)
        {
            x=getInt();
            Update(i,-x);
        }
        int tip;
    while(m--)
    {
        tip=getInt();
        if(tip==0)
        {
           x=getInt();
           y=getInt();
           Update(x,y);
        }
        else
        {
           x=getInt();
           y=getInt();
            printf("%d\n",Query(y)-Query(x-1));
        }

    }


    return 0;
}