Cod sursa(job #1798114)

Utilizator Rocamadour1497Alexandru Martiniuc Rocamadour1497 Data 4 noiembrie 2016 21:20:54
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <fstream>

using namespace std;

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


int n, m, x, y, z, c;
int a[15001];

int query(int poz)
{
    int s = 0;
    for ( int i = poz; i; i -= i & -i)
        s += a[i];
    return s;
}

void update(int poz, int v)
{
    for ( int i = poz; i <= n; i += i & -i )
        a[i] -= v;
}
void update1(int poz, int v)
{
    for ( int i = poz; i <= n; i += i & -i )
        a[i] += v;
}


int main()
{

    f >> n >> m;
    for(int i = 1; i <= n; ++i)
    {
        f >> c;
        update1(i, c);

    }
    for(int i = 1; i <= m; ++i)
    {
        f >> x >> y >> z;
        if(x == 0)
            update(y, z);
        else
            g << query(z) - query(y-1) << '\n';

    }
    return 0;
}