Pagini recente » Cod sursa (job #2499268) | Cod sursa (job #2181199) | Cod sursa (job #970730) | Cod sursa (job #3030386) | Cod sursa (job #2932025)
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <assert.h>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
const int MAX_SIZE = 100001;
int n, noOperations;
int MaxArb[4 * MAX_SIZE + 66];
int start, finish, val, pos, maxValue;
inline int maximum(int a, int b) {
if (a > b) {
return a;
}
return b;
}
void update(int nod, int left, int right) {
if (left == right) {
MaxArb[nod] = val;
return;
}
int div = (left + right) / 2;
if (pos <= div) {
update(2 * nod, left, div);
} else {
update(2 * nod + 1, div + 1, right);
}
MaxArb[nod] = maximum(MaxArb[2 * nod], MaxArb[2 * nod + 1]);
}
void query(int nod, int left, int right) {
if (start <= left && right <= finish) {
if (maxValue < MaxArb[nod]) {
maxValue = MaxArb[nod];
}
return;
}
int div = (left + right) / 2;
if (start <= div) {
query(2 * nod, left, div);
}
if (div < finish) {
query(2 * nod + 1, div + 1, right);
}
}
int main() {
std::ios::sync_with_stdio(false);
int task, a, b;
fin >> n >> noOperations;
for (int i = 1; i <= n; ++i) {
int element;
fin >> element;
pos = i;
val = element;
update(1, 1, n);
}
for (int i = 1; i <= noOperations; ++i) {
fin >> task >> a >> b;
if (task == 0) {
maxValue = -1;
start = a;
finish = b;
query(1, 1, n);
fout << maxValue << "\n";
} else {
pos = a;
val = b;
update(1, 1, n);
}
}
}