Cod sursa(job #2454939)

Utilizator IliesiDanielDaniel IliesiDaniel Data 10 septembrie 2019 14:11:19
Problema Datorii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.54 kb
// ============================================================================

#include <iostream>
#include <fstream>
#include <vector>

// ============================================================================

using namespace std;

// ============================================================================

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

// ============================================================================

int main (void)
{
	// ------------------------------------------------------------------------

	vector <int> 	datorii;
	bool 			tip;
	int 			n, m;
	int 			zi, suma;
	int 			zis, zif;

	// ------------------------------------------------------------------------
	// We're indexing from 1.

	datorii.push_back(0);

	// ------------------------------------------------------------------------
	// Initial file read.

	fin >> n >> m;

	for (zi = 1; zi <= n; zi++)
	{
		fin >> suma;

		datorii.push_back (suma);
	}

	// ------------------------------------------------------------------------
	// Reading and processing the rest of the file.

	for (int operatiune = 0; operatiune < m; operatiune++)
	{
		fin >> tip;

		if (tip == false)
		{
			fin >> zi >> suma;

			datorii [zi] -= suma;
		}
		else
		{
			fin >> zis >> zif;
			suma = 0;

			for (zi = zis; zi <= zif; zi++)
			{
				suma += datorii [zi];
			}

			cout << suma << endl;
		}
	}

	// ------------------------------------------------------------------------

	return 0;
}

// ============================================================================