Pagini recente » Cod sursa (job #2022163) | Cod sursa (job #1703492) | Cod sursa (job #2053569) | Monitorul de evaluare | Cod sursa (job #1749233)
#include <fstream>
#include <iostream>
#include <vector>
#include <climits>
#include <math.h>
#define dim 100001
using namespace std;
int m, n, aux, start = 0, p1, p2, arb_size, a, b, pos, val, arbore[dim * 4 + 66], mid;
ifstream infile("arbint.in");
ofstream outfile("arbint.out");
void constructTree (int start, int end, int poz) {
if (start == end) {
arbore[poz] = val;
return;
}
mid = (start + end) / 2;
if (pos <= mid)
constructTree(start, mid, poz * 2 + 1);
else constructTree(mid + 1, end, poz * 2 + 2);
arbore[poz] = max(arbore[poz * 2 + 1], arbore[poz * 2 + 2]);
}
int findMax (int start, int end, int poz) {
if (start >= a && b >= end)
return arbore[poz];
if (b < start || a > end)
return INT_MIN;
mid = (start + end) / 2;
int stanga = findMax(start, mid, poz * 2 + 1);
int dreapta = findMax(mid + 1, end, poz * 2 + 2);
return max(stanga, dreapta);
}
int main() {
infile >> n >> m;
for (int i = 0; i < n; i ++) {
infile >> aux;
pos = i;
val = aux;
constructTree (0, n - 1, 0);
}
infile >> aux;
while (aux == 1) {
infile >> p1 >> p2 >> aux;
pos = p1 - 1;
val = p2;
constructTree (0, n - 1, 0);
start ++;
}
for (int i = start; i < m; i ++) {
infile >> p1 >> p2;
a = p1 - 1;
b = p2 - 1;
if (aux == 0)
outfile << findMax(0, n - 1, 0) << endl;
else {
pos = p1 - 1;
val = p2;
constructTree (0, n - 1, 0);
}
if (i != m - 1)
infile >> aux;
}
return 0;
}