Cod sursa(job #1506343)

Utilizator dorin31Geman Dorin Andrei dorin31 Data 20 octombrie 2015 15:16:44
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <iostream>
#include <fstream>
#define zeros(x) ( (x ^ (x - 1)) & x )

using namespace std;

ifstream fin("datorii.in");
ofstream fout("datorii.out");

int n,m,AIB[15001];

void update(int poz, int val)
{
    for ( ;poz<=n; poz+=zeros(poz))
        AIB[poz]+=val;
}

int sum(int poz)
{
    int s=0;
    for ( ;poz; poz-=zeros(poz))
        s+=AIB[poz];
    return s;
}

int main()
{
    fin>>n>>m;
    int x;
    for (int i=1; i<=n; ++i)
    {
        fin>>x;
        update(i,x);
    }
    for (int i=1; i<=m; ++i)
    {
        int a,b,c;
        fin>>a>>b>>c;
        if (!a) update(b,-c);
        else fout<<sum(c)-sum(b-1)<<'\n';
    }
    return 0;
}