Cod sursa(job #1249195)

Utilizator azkabancont-vechi azkaban Data 26 octombrie 2014 17:41:08
Problema Arbori de intervale Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.15 kb
#include <fstream>
using namespace std;
ifstream cin("arbint.in");
ofstream cout("arbint.out");
int n,i,j,op,l,r,q,solutie;
int Stree[400013];

void update (int nod, int st, int dr, int poz, int val)
{
 if (st==dr) Stree[nod]=val;
       else {
             int middle=(st+dr)/2;
             if (poz<=middle) update(nod*2,st,middle,poz,val);
                         else update(nod*2+1,middle+1,dr,poz,val);
             Stree[nod]=max(Stree[nod*2],Stree[nod*2+1]);
             }
}

void query ( int nod, int st, int dr, int a, int b)
{
 if (st>=a && b>=dr) solutie=max(solutie,Stree[nod]);
             else {
                   int middle=(st+dr)/2;
                   if (a<=middle) query(nod*2,st,middle,a,b);
                   if (b>middle) query(nod*2+1,middle+1,dr,a,b);
                   }
}

int main()
{
 cin>>n>>q;
 for (i=1;i<=n;++i)
  {
   cin>>op;
   update(1,1,n,i,op);
  }
  while(q--)
   {
    cin>>op>>l>>r;
    if (op==0){
               solutie=-1<<30;
               query(1,1,n,l,r);
               cout<<solutie<<"\n";
               }
    if (op==1) update (1,1,n,l,r);       
    }
   
return 0;
}