Pagini recente » Cod sursa (job #2093557) | Cod sursa (job #3033463) | Cod sursa (job #1851327) | Cod sursa (job #2894439) | Cod sursa (job #1863343)
#include <bits/stdc++.h>
#define fastcall __attribute__((always_inline, hot, optimize("O3")))
using namespace std;
static constexpr int maxn = 1e5 + 10;
static ifstream f("arbint.in");
static ofstream g("arbint.out");
static char buf[maxn], *p = buf, *ep = buf + sizeof(buf);
static int n, m, v[maxn], arb[2*maxn] = {};
fastcall inline static void adv(){
if(++p == ep) f.read(p=buf, sizeof(buf)); }
fastcall inline static void setup_parsare(){
f.read(buf, sizeof(buf)); }
fastcall inline static int get_int(){
int rhs = 0;
while(*p < '0') adv();
while(*p >= '0') rhs = 10 * rhs + *p - '0', adv();
return rhs; }
fastcall inline static void build_arbint(){
copy(v, v+n, arb+n);
for(int i = n-1; i; --i) arb[i] = max(arb[2*i], arb[2*i+1]); }
fastcall inline static void update(int poz, const int val){
arb[poz += n] = val;
for(poz /= 2; poz; poz /= 2)
arb[poz] = max(arb[2*poz], arb[2*poz+1]); }
fastcall inline static int query(int st, int dr){
int r = 0;
for(st += n, dr += n+1; st < dr; st /= 2, dr /= 2){
if(st%2) r = max(r, arb[st++]);
if(dr%2) r = max(r, arb[--dr]); }
return r; }
int main(){
n = get_int(), m = get_int();
for(int i = 0; i < n; ++i) v[i] = get_int();
build_arbint();
for(int i = 0, t, a, b; i < m; ++i){
t = get_int(), a = get_int(), b = get_int();
if(t == 0) g << query(a-1, b-1) << '\n';
else update(a-1, b); }
return 0; }