Cod sursa(job #3141090)

Utilizator verde.cristian2005Verde Flaviu-Cristian verde.cristian2005 Data 12 iulie 2023 11:23:05
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>
using namespace std;

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

int aib[150001], n;

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

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

long long query(int poz)
{
    long long s = 0;
    for(; poz > 0; poz -= lsb(poz))
        s += aib[poz];
    return s;
}

int main()
{
    int m, t, x, a, b;
    in >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        in >> x;
        update(i, x);
    }
    for(int i = 1; i <= m; i++)
    {
        in >> t >> a >> b;
        if(t == 0)
            update(a, -b);
        else
            out << query(b) - query(a - 1) << '\n';
    }
    return 0;
}