Pagini recente » Cod sursa (job #2723952) | Cod sursa (job #677408) | Cod sursa (job #3294473) | Cod sursa (job #2940579) | Cod sursa (job #3292966)
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("inline,unroll-loops,fast-math")
#pragma GCC target ("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
class inParser {
private:
FILE *fin; char *buff; int id;
char readCh( ) {
++id;
if (id == 4096) { id = 0; fread(buff, sizeof(char), 4096, fin); }
return buff[id];
}
public:
inParser (const char *name) {
fin = fopen(name, "r");
buff = new char[4096]( );
id = 4095;
}
inParser& operator >> (int& num) {
char ch;
while (!isdigit(ch = readCh( )));
num = ch - '0';
while (isdigit(ch = readCh( )))
num = num * 10 + ch - '0';
return *this;
}
};
const string fileName = "arbint";
inParser in ((fileName + ".in").c_str( ));
ofstream out (fileName + ".out");
const int maxsze = 1e5 + 2;
const int inf = 0x3f3f3f3f;
const int modulo = 1e9 + 7;
int n, m;
int tree[2 * maxsze];
int maxTree(int l, int r) {
l += n; r += n;
int ans = -inf;
while (l <= r) {
if ((l & 1) == 1) ans = max(ans, tree[l++]);
if ((r & 1) == 0) ans = max(ans, tree[r--]);
l >>= 1; r >>= 1;
}
return ans;
}
void updateTree(int pos, int elem) {
pos += n; tree[pos] = elem;
pos >>= 1;
while (pos >= 1) {
tree[pos] = max(tree[(pos << 1)], tree[(pos << 1) + 1]);
pos >>= 1;
}
}
int main( ) {
in >> n >> m;
int elem;
for (int i = 1; i <= n; ++i) {
in >> elem;
updateTree(i, elem);
}
int op, a, b;
for (int i = 1; i <= m; ++i) {
in >> op >> a >> b;
switch ( op ) {
case 0: out << maxTree(a, b) << '\n'; break;
case 1: updateTree(a, b); break;
}
}
return 0;
}