Cod sursa(job #2379041)

Utilizator RaresLiscanLiscan Rares RaresLiscan Data 12 martie 2019 20:36:16
Problema Datorii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <bits/stdc++.h>

using namespace std;

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

unsigned int aib[15005];

void updateBIT (int idx, int val, int n)
{
    while (idx <= n) {
        aib[idx] += val;
        idx += ( (idx ^ (idx - 1)) & idx );
    }
}

int read (int idx)
{
    int sum = 0;
    while (idx > 0) {
        sum += aib[idx];
        idx -= ( (idx ^ (idx - 1)) & idx );
    }
    return sum;
}

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