Cod sursa(job #1018893)

Utilizator hotfixVasile Pantelescu hotfix Data 30 octombrie 2013 06:13:15
Problema Datorii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>
using namespace std;

int main()
{
	const char* file_name = "datorii.in";
	const char* file_out = "datorii.out";
	int N, M;

	ifstream ifs(file_name);
	ofstream ofs(file_out);
	ifs>>N>>M;
	//read the vector
	int *a = new int[N+1];
	for (int n = 1; n <= N; n++) ifs>>a[n];
	
	//read the operations one by one and process them
	for (int m = 1; m <= M; m++)
	{
		int op_type, X, Y;
		ifs>>op_type>>X>>Y;
		
		//process the operations
		if (op_type == 0) a[X] -= Y;
		else //(op_type == 1)
		{
			unsigned long long sum = 0;
			for (int n = X; n <= Y; n++) sum += a[n];
			//write the result to the file
			ofs<<sum<<"\n";
		}
	}

	//release the memory
	delete[] a;
	//close the files
	ifs.close();
	ofs.close();

	return 0;
}