Pagini recente » Cod sursa (job #2190371) | Cod sursa (job #2414305) | Cod sursa (job #2205622) | Cod sursa (job #2413582) | Cod sursa (job #2600556)
#include <stdio.h>
#include <math.h>
#define N 1<<18
int n, q, tree[N];
static inline int max (const int a, const int b) {
return a>b?a:b;
}
void update (int i, int x) {
i+=n-1;
tree[i]=x;
while (i>>=1)
tree[i]=max(tree[i<<1], tree[(i<<1)+1]);
}
int query (int l, int r) {
int ans=0;
l+=n-1;
r+=n-1;
while (l<=r) {
if (l&1) {
ans=max(ans, tree[l]);
++l;
}
if (!(r&1)) {
ans=max(ans, tree[r]);
--r;
}
l>>=1;
r>>=1;
}
return ans;
}
int main () {
FILE *fin=fopen("arbint.in", "r"),
*fout=fopen("arbint.out", "w");
fscanf(fin, "%d%d", &n, &q);
int i, lg=log2(n), save=n, x, key, a, b;
if (1<<lg!=n)
n=1<<lg+1;
for (i=1; i<=save; i++) {
fscanf(fin, "%d", &x);
update(i, x);
}
for (; q; q--) {
fscanf(fin, "%d%d%d", &key, &a, &b);
if (key)
update(a, b);
else
fprintf(fout, "%d\n", query(a, b));
}
return 0;
}