Cod sursa(job #1143193)

Utilizator thereauFMI Sandu Robert Stelian thereau Data 14 martie 2014 21:57:56
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
//#include "stdafx.h"
#include <fstream>
#include <vector>
//#include <iostream>
using namespace std;
vector<int>sume;
inline void sum(int poz,int val)
{
	if (poz > 0)
	{
		sume.at(poz) = val+sume.at(poz-1);
	}
	else
		sume.at(poz) = val;
	
}
inline void actualizare(int poz, int val)
{
	for (int i = poz - 1; i < sume.size(); i++)
		sume.at(i) += val;
}

int main()
{
	ifstream citire("datorii.in");
	int n, m, x;
	citire >> n >> m;	
	sume.resize(n);
	ofstream scriere("datorii.out");
	for (int i = 0; i < n; i++)
	{
		citire >> x;
		sum(i, x);
	}
	for (int i = 0; i < m; i++)
	{
		int a, b, c;
		citire >> a >> b >> c;
		if (a == 0)
			actualizare(b, -c);
		else
		{
			if (b == 1)
			{
				scriere << sume.at(c - 1) << "\n";
			}
			else
			{
				scriere << sume.at(c - 1) - sume.at(b - 2) << "\n";
			}
		}
	}
	citire.close();
	scriere.close();
	//system("PAUSE");
	return 0;
}