Cod sursa(job #2336596)

Utilizator andreigeorge08Sandu Ciorba andreigeorge08 Data 5 februarie 2019 12:15:33
Problema Datorii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>

using namespace std;

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

int d[15005], n, q;

void Update(int dest, int v)
{
    for(int i = dest; i <= n; i += (i & (-i)))
        d[i] += v;
}

int Query(int x)
{
    int sum = 0;

    for(int i = x; i >= 1; i -= (i & (-i)))
        sum += d[i];

    return sum;
}

void Citire()
{
    int x, y, op;

    fin >> n >> q;
    for(int i = 1; i <= n; i++)
    {
        fin >> x;
        Update(i, x);
    }

    for(int i = 1; i <= q; i++)
    {
        fin >> op >> x >> y;
        if(op == 0)
            Update(x, -y);
        else fout << Query(y) - Query(x - 1) << "\n";
    }
}

int main()
{
    Citire();
    return 0;
}