Cod sursa(job #2316455)

Utilizator ezioconnorVlad - Gabriel Iftimescu ezioconnor Data 11 ianuarie 2019 19:05:21
Problema Datorii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>

using namespace std;

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

int AIB[15155];
int n, m;

inline int zeros(int x)
{
    return x & (-x);
}

void update(int x, int c)
{
    for (int i = x; i <= n; i += zeros(i))
        AIB[i] += c;
}

int compute(int x)
{
    int rez = 0;
    for (int i = x; i > 0; i -= zeros(i))
        rez += AIB[i];
    return rez;
}

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