Pagini recente » Cod sursa (job #1708286) | Cod sursa (job #2613621) | Cod sursa (job #2982263) | Cod sursa (job #2952925) | Cod sursa (job #2155452)
#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;
}