Pagini recente » Cod sursa (job #1073050) | Cod sursa (job #678013) | Cod sursa (job #102659) | Cod sursa (job #1650699) | Cod sursa (job #2082670)
#include <stdio.h>
#define MAX_N 100000
int N, Q;
int tree[MAX_N * 2 + 1];
#define fastcall __attribute__((optimize("-O3")))
#define inline __inline__ __attribute__((always_inline))
#include <ctype.h>
const int MAX_BUFF = 65536 * 27;
int pos = 0;
char buff[MAX_BUFF];
char c;
inline fastcall void fscanf(int &x) {
x = 0;
do {
c = buff[pos++];
} while (!isdigit(c));
do {
x = (x << 3) + (x << 1) + c - '0';
c = buff[pos++];
} while (isdigit(c));
}
inline int MAX(int X, int Y) {
return X > Y ? X : Y;
}
void update(int x, int val) {
x += N;
tree[x] = val;
while (x > 1) {
tree[x >> 1] = MAX(tree[x], tree[x ^ 1]);
x >>= 1;
}
}
int query(int a, int b) {
int ans = 0;
a += N;
b += N;
while (a < b) {
if (a & 1) {
ans = MAX(ans, tree[a++]);
}
if (b & 1) {
ans = MAX(ans, tree[--b]);
}
a >>= 1;
b >>= 1;
}
return ans;
}
int main(void) {
int i;
FILE *f = fopen("arbint.in", "r");
fread(buff, 1, MAX_BUFF, f);
fscanf(N);
fscanf(Q);
for (i = 1; i <= N; i++) {
fscanf(tree[i + N]);
}
for (i = N; i >= 1; i--) {
tree[i] = MAX(tree[i << 1], tree[(i << 1) | 1]);
}
freopen("arbint.out", "w", stdout);
int task, a, b;
while (Q) {
fscanf(task);
fscanf(a);
fscanf(b);
if (task == 0) {
fprintf(stdout, "%d\n", query(a, b + 1));
} else {
update(a, b);
}
Q--;
}
freopen("chimic.out", "w", stdout);
fprintf(stdout, "%lld\n", tree[1]);
return 0;
}