Cod sursa(job #2152814)

Utilizator AlexnolifeAlexandru Ica Alexnolife Data 5 martie 2018 20:16:02
Problema Arbori de intervale Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <iostream>
#include <fstream>
#include <array>

using uint64 = unsigned long long;
using uchar  = unsigned char;

std::ifstream f("arbint.in");
std::ofstream g("arbint.out");

enum OpType : int { MAX = 0, CHANGEVAL = 1 };

struct Operation
{
	int type;
	uint64 a;
	uint64 b;
};

uint64 arrSize;
uint64 numOfop;
uint64 max;

std::array<uint64, 100000U> v;

void Read()
{
	f >> arrSize >> numOfop;

	size_t i;

	for (i = 0U; i < arrSize; ++i) {
		f >> v[i];
	}

	Operation op;

	for (i = 0U; i < numOfop; ++i) {
		f >> op.type >> op.a >> op.b;

		max = 0ULL;

		switch (op.type)
		{
		case OpType::MAX: {
			for (size_t j = op.a - 1; j < op.b; ++j) {
				if (v[j] > max) {
					max = v[j];
				}
			}

			g << max << "\n";

			break;
		}
		case OpType::CHANGEVAL: {
			v[op.a - 1] = op.b;

			break;
		}
		}
	}
}

int main()
{
	Read();

	std::cin.get();

	return 0;
}