Cod sursa(job #1676814)

Utilizator vladttturcuman vlad vladtt Data 6 aprilie 2016 10:24:30
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
// Datorii.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <fstream>

#define AIB(x) ((x^(x-1))&x)
#define NMax 15010

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

int MAx, n, i, m, x, a, b,t,Max;

int _aib[NMax];

void _Scade(int a, int b)
{
	for (int i = b; i <= Max; i += AIB(i))
		_aib[i] -= a;
}

int Query(int b)
{
	int s = 0;
	for (int i = b; i >= 1; i -= AIB(i))
	{
		s += _aib[i];
	}
	return s;
}

int main()
{

	fin >> n >> m;

	Max = n;

	for (i = 1; i <= n; i++)
	{
		fin >> x;
		_Scade(-x,i);
	}

	for (i = 1; i <= m; i++)
	{
		fin >> t >> a >> b;
		if (!t)
		{
			_Scade(b, a);
		}
		else
			fout << Query(b) - Query(a-1)<<'\n';
	}

    return 0;
}