Cod sursa(job #2155452)

Utilizator AlexnolifeAlexandru Ica Alexnolife Data 7 martie 2018 20:54:21
Problema Arbori de intervale Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 1.25 kb
#include <iostream>
#include <fstream>
#include <array>

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

template<typename T, size_t rows, size_t cols>
using matrix = std::array<std::array<T, cols>, rows>;

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;
matrix<uint64, 10000U, 10000U> m;

void ConstructMatrix()
{
	for (size_t i = 0U; i < arrSize; ++i) {
		for (size_t j = i; j < arrSize; ++j) {
			if (i == j) {
				m[i][j] = v[i];
			}
			else {
				m[i][j] = std::max(v[j], m[i][j - 1U]);
			}
		}
	}
}

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

	size_t i;

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

	ConstructMatrix();

	Operation op;

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

		max = 0ULL;

		switch (op.type)
		{
		case OpType::MAX: {

			g << m[op.a - 1U][op.b - 1U] << "\n";

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

			ConstructMatrix();

			break;
		}
		}
	}
}

int main()
{
	Read();

	std::cin.get();

	return 0;
}