Pagini recente » Cod sursa (job #904547) | Cod sursa (job #1932692) | Cod sursa (job #2479924) | Cod sursa (job #1396746) | Cod sursa (job #1511399)
// Arbori de intervale.cpp : Defines the entry point for the console application.
//
#include <fstream>
///#include "stdafx.h"
using namespace std;
const int Max = 100001;
int N, M;
int Arbore[4 * Max + 66];
int start, finish, maximum, position, value;
inline int MAX(int a, int b) {
if (a > b) return a;
else return b;
}
void update(int nod, int left, int right) {
if (left == right) {
Arbore[nod] = value;
return;
}
int middle = (left + right) / 2;
if (position <= middle) update(2 * nod, left, middle);
else update(2 * nod + 1, middle + 1, right);
Arbore[nod] = MAX(Arbore[2 * nod], Arbore[2 * nod + 1]);
}
void query(int nod, int left, int right) {
if (start <= left && right <= finish){
if (maximum < Arbore[nod])
maximum = Arbore[nod];
return;
}
int middle = (left + right) / 2;
if (start <= middle) query(2 * nod, left, middle);
if (middle < finish) query(2 * nod + 1, middle + 1, right);
}
int main() {
int X, A, B;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
fin >> N >> M;
for (int i = 1; i <= N; ++i) {
fin >> X;
position = i, value = X;
update(1, 1, N);
}
for (int i = 1; i <= M; ++i) {
fin >> X >> A >> B;
if (X == 0) {
maximum = -1;
start = A, finish = B;
query(1, 1, N);
fout << maximum << "\n";
}
else {
position = A, value = B;
update(1, 1, N);
}
}
return 0;
}