Pagini recente » Cod sursa (job #2054795) | Cod sursa (job #211545) | Profil M@2Te4i | Cod sursa (job #104865) | Cod sursa (job #1778664)
#include <fstream>
#include <sstream>
#include <cstdio>
#include <algorithm>
using namespace std;
class InputReader {
public:
InputReader() {}
InputReader(const char *file_name) {
input_file = fopen(file_name, "r");
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
template <typename T>
inline InputReader &operator >>(T &n) {
while(buffer[cursor] < '0' || buffer[cursor] > '9') {
advance();
}
n = 0;
while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
n = n * 10 + buffer[cursor] - '0';
advance();
}
return *this;
}
void close() {
fclose(input_file);
}
private:
FILE *input_file;
static const int SIZE = 1 << 17;
int cursor;
char buffer[SIZE];
inline void advance() {
++ cursor;
if(cursor == SIZE) {
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
}
};
const int N = 1e5;
int n;
int t[2 * N];
void build() {
for (int i = n - 1; i > 0; -- i)
t[i] = max(t[i << 1], t[i << 1 | 1]);
}
void update(int p, int value) {
for (t[p += n] = value; p > 1; p >>= 1)
t[p>>1] = max(t[p], t[p ^ 1]);
}
int query(int l, int r) {
int res = 0;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
res = max(res, t[l ++]);
if (r & 1)
res = max(res, t[-- r]);
}
return res;
}
int main()
{
InputReader cin("arbint.in");
ofstream cout("arbint.out");
int m = 0;
cin >> n >> m;
for (int i = 0; i < n; ++ i)
cin >> t[n + i];
build();
stringstream ss;
bool type;
int a, b;
while (m --) {
cin >> type >> a >> b;
if (!type)
ss << query(a - 1, b) << '\n';
else
update(a - 1, b);
}
cout << ss.str();
cin.close();
cout.close();
return 0;
}