Cod sursa(job #2430846)

Utilizator AlexNeaguAlexandru AlexNeagu Data 16 iunie 2019 21:39:00
Problema Arbori de intervale Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.39 kb
#include<bits/stdc++.h>
#pragma gcc optimize("O3")
#define all(s) s.begin(),s.end()
#define rc(x) return cout<<x<<endl,0
#define forn(i,n) for(int i=0;i<int(n);i++)
#define len(a) (int) (a).size()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const int nmax=100005;
const int mod=1e9+7;
const ll inf=0x3f3f3f3f3f3f3f3f;
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
int n, m;
vector < int > a(nmax), b(2 * nmax, 0);
int query(int lft, int rgt)
{
  lft += n; rgt += n;
  int mx = 0;
  while (lft <= rgt)
  {
    if (lft % 2 == 1) mx = max(mx, b[lft++]);
    if (rgt % 2 == 0) mx = max(mx, b[rgt--]);
    lft /= 2; rgt /= 2;
  }
  return mx;
}
int update(int pos, int val)
{
  pos += n;
  b[pos] = val;
  for (pos / 2;  pos >= 1; pos /= 2)
  b[pos] = max(b[2 * pos], b[2 * pos + 1]);
}
int main()
{
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  ios_base::sync_with_stdio(0); cin.tie(0);
  fin >> n >> m;
  for (int i = 1; i <= n; i++) fin >> a[i];
  for (int i = 1; i < n; i++) b[n + i] = a[i];
  for (int i = n - 1; i > 0; i--) b[i] = max(b[2 * i], b[2 * i + 1]);
  for (int i = 1; i <= m; i++)
  {
    int operation, x, y;
    fin >> operation >> x >> y;
    if (!operation) fout << query(x, y) << "\n" ; else  update(x, y);
  }
}