Cod sursa(job #3247148)

Utilizator ridicheTudor Diaconu ridiche Data 5 octombrie 2024 20:03:23
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>

using namespace std;

ifstream in;
ofstream out;

int n, m, aib[15005];

void update(int i, int x)
{
    while (i <= n)
    {
        aib[i] += x;
        i += i & -i;
    }
}

int sp(int i)
{
    int r = 0;
    while (i > 0)
    {
        r += aib[i];
        i -= i & -i;
    }
    return r;
}

int main()
{
    in.open("datorii.in");
    out.open("datorii.out");
    in >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        int x;
        in >> x;
        update(i, x);
    }
    for (int i = 0; i < m; i++)
    {
        int c, a, b;
        in >> c >> a >> b;
        if (c == 0)
        {
            update(a, -b);
        }
        if (c == 1)
        {
            out << sp(b) - sp(a-1) << "\n";
        }
    }
    return 0;
}