Cod sursa(job #2019342)

Utilizator workwork work work Data 7 septembrie 2017 15:49:08
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <bits/stdc++.h>

using namespace std;

ifstream F("datorii.in");
ofstream G("datorii.out");

int n, m, x, q, a, b, aib[15005];

void upd(int pos, int val)
{
    while(pos <= n)
    {
        aib[pos] += val;
        pos += pos & (-pos);
    }
}

int query(int pos)
{
    int sum = 0;
    while(pos > 0)
    {
        sum += aib[pos];
        pos -= pos & (-pos);
    }
    return sum;
}

int main()
{
    F >> n >> m;
    for(int i = 1; i <= n; ++ i) F >> x, upd(i, x);
    while(m--)
    {
        F >> q >> a >> b;
        if(q) G << query(b) - query(a-1) << '\n';
        else upd(a, -b);
    }
    return 0;
}