Cod sursa(job #3237946)

Utilizator tsg38Tsg Tsg tsg38 Data 14 iulie 2024 15:33:11
Problema Arbori de intervale Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ifstream fin( "arbint.in" );
ofstream fout( "arbint.out" );

const int DIM = 1e5 + 1;

int aint[2 * DIM], n;

void upd( int pos, int val ) {
  int node = n + pos - 1;
  aint[node] = val;
  while ( node ) {
	node >>= 1;
	aint[node] = max(aint[2 * node], aint[2 * node + 1]);
  }
}
int qry( int l, int r ) {
  int res = 0;
  l += n - 1, r += n - 1;
  while ( l < r ) {
	if ( l & 1 ) {
	  res = max(res, aint[l++]);
	}
    if ( r & 1 ) {
	  res = max(res, aint[--r]);
	}
	l >>= 1;
	r >>= 1;
  }
  if ( l == r ) res = max(res, aint[l]);
  return res;
}

int main() {
  ios_base::sync_with_stdio(0);
  fin.tie(0);
  int q, tp, x, y;

  fin >> n >> q;
  for ( int i = 1; i <= n; ++i ) {
    fin >> x;
    upd(i, x);
  }
  while ( q-- ) {
	fin >> tp >> x >> y;
	if ( tp == 0 ) {
	  fout << qry(x, y) << "\n";
	} else {
	  upd(x, y);
	}
  }
  fin.close();
  fout.close();
  return 0;
}