Pagini recente » Cod sursa (job #2266777) | Cod sursa (job #306926) | Cod sursa (job #249781) | Cod sursa (job #1394803) | Cod sursa (job #2155465)
#include <fstream>
#include <array>
#include <vector>
#include <algorithm>
#include <iterator>
using uint64 = unsigned long long;
using uchar = unsigned char;
template<typename T>
using matrix = std::vector<std::vector<T>>;
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::vector<uint64> v;
matrix<uint64> 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;
m.resize(arrSize);
std::for_each(std::begin(m), std::end(m), [](std::vector<uint64>& vec) { vec.resize(arrSize); });
v.reserve(arrSize);
size_t i;
uint64 x;
for (i = 0U; i < arrSize; ++i) {
f >> x;
v.emplace_back(x);
}
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();
return 0;
}