Pagini recente » Cod sursa (job #2628042) | Statistici Anton Stefan (Stefan_A) | Cod sursa (job #2327852) | Cod sursa (job #781535) | Cod sursa (job #1557468)
#include <bits/stdc++.h>
using namespace std;
const int kMaxN = 100000;
const int kBuffSize = 655536;
int T[2 * kMaxN];
inline char getChar() {
static char buff[kBuffSize];
static int pos = kBuffSize;
if (pos == kBuffSize) {
fread_unlocked(buff, 1, kBuffSize, stdin);
pos = 0;
}
return buff[pos++];
}
inline int readInt() {
int q = 0;
char c;
do {
c = getChar();
} while (!isdigit(c));
do {
q = (q << 1) + (q << 3) + (c - '0');
c = getChar();
} while (isdigit(c));
return q;
}
char outBuff[kBuffSize];
int outPtr;
inline void putChar(const char &C) {
outBuff[outPtr++] = C;
if (outPtr == kBuffSize) {
fwrite_unlocked(outBuff, 1, kBuffSize, stdout);
outPtr = 0;
}
}
inline void writeInt(int X) {
char digs[10];
int n = 0, q;
do {
q = X / 10;
digs[n++] = X - (q << 1) - (q << 3) + '0';
X = q;
} while (X);
while (n--) {
putChar(digs[n]);
}
putChar('\n');
}
int main(void) {
freopen("arbint.in", "r", stdin);
freopen("arbint.out", "w", stdout);
int N, Q;
int opType, st, fn;
int rez;
N = readInt(); Q = readInt();
for (int i = 0; i < N; i++) {
T[i + N] = readInt();
}
for (int i = N - 1; i; i--) {
T[i] = max(T[i << 1], T[(i << 1) | 1]);
}
while (Q--) {
opType = readInt();
if (!opType) {
st = N + readInt() - 1; fn = N + readInt() - 1;
rez = 0;
while (st <= fn) {
rez = max(rez, max(T[st], T[fn]));
st = (st + 1) >> 1;
fn = (fn - 1) >> 1;
}
writeInt(rez);
} else {
fn = N + readInt() - 1;
T[fn] = readInt();
while (fn > 1) {
st = fn >> 1;
T[st] = max(T[fn], T[fn ^ 1]);
fn = st;
}
}
}
fclose(stdin);
fwrite_unlocked(outBuff, 1, outPtr, stdout);
fclose(stdout);
return 0;
}