Pagini recente » Istoria paginii jc2019/clasament | gardening | Cod sursa (job #897785) | Sedinta 2009-01-26 | Cod sursa (job #1761946)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
const int NMAX = 4 * 1e5 + 1;
int n, m;
int arbInt[NMAX];
int updatePos, updateVal, xQuery, yQuery;
int maxQuery;
inline int getMax(int a, int b) {
return a > b ? a : b;
}
void update(int node, int lo, int hi) {
if (lo == hi) {
arbInt[node] = updateVal;
return;
}
int mid = (lo + hi) / 2;
if (updatePos <= mid)
update(2 * node, lo, mid);
else
update(2 * node + 1, mid + 1, hi);
arbInt[node] = getMax(arbInt[2 * node], arbInt[2 * node + 1]);
}
void query(int node, int lo, int hi) {
if (xQuery <= lo and hi <= yQuery) {
maxQuery = getMax(maxQuery, arbInt[node]);
return;
}
int mid = (lo + hi) / 2;
if (xQuery <= mid)
query(2 * node, lo, mid);
if (mid < yQuery)
query(2 * node + 1, mid + 1, hi);
}
int main()
{
int x, a, b;
fin >> n >> m;
for (int i = 1; i <= n; ++i) {
fin >> x;
updatePos = i;
updateVal = x;
update(1, 1, n);
}
for (int i = 1; i <= m; ++i) {
fin >> x >> a >> b;
if (x == 0) {
xQuery = a;
yQuery = b;
maxQuery = -1;
query(1, 1, n);
fout << maxQuery << '\n';
}
else {
updatePos = a;
updateVal = b;
update(1, 1, n);
}
}
return 0;
}