Cod sursa(job #1793512)

Utilizator cri25Berbecariu Crina cri25 Data 31 octombrie 2016 09:23:26
Problema Datorii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>

using namespace std;

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


int n, m, x, y, op, 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()
{

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

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

    }
    return 0;
}