Mai intai trebuie sa te autentifici.
Cod sursa(job #2964564)
Utilizator | Data | 13 ianuarie 2023 11:06:57 | |
---|---|---|---|
Problema | Arbori de intervale | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 1.86 kb |
#include <fstream>
#include <ctime>
#include <random>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
///hopefully not TLE?
///T ul trebuie sa aiba implementat <
template<typename T>
class AINT_MAX
{
int n;
vector<T>aint;
T build(int nod,int st,int dr,vector<T>&a)
{
if(st==dr)
{
aint[nod]=a[st];
return aint[nod];
}
int m=(st+dr>>1);
aint[nod]=max(build(2*nod,st,m,a),build(2*nod+1,m+1,dr,a));
return aint[nod];
}
T update(int nod,int st,int dr,const int poz,const int val)
{
if(dr<poz || st>poz)return aint[nod];
if(st==dr)
{
aint[nod]=val;
return aint[nod];
}
int m=(st+dr>>1);
aint[nod]=max(update(2*nod,st,m,poz,val),update(2*nod+1,m+1,dr,poz,val));
return aint[nod];
}
T query(int nod,int st,int dr,const int l,const int r)
{
if(dr<l || st>r)return T(0);
if(l<=st && dr<=r)return aint[nod];
int m=(st+dr>>1);
return max(query(2*nod,st,m,l,r),query(2*nod+1,m+1,dr,l,r));
}
public:
AINT_MAX(vector<T>&a)
{
n=(int)a.size();
aint=vector<int>(4*n+1);
build(1,0,n-1,a);
}
T query(int l,int r)
{
return query(1,0,n-1,l,r);
}
void update(int poz,int val)
{
T x=update(1,0,n-1,poz,val);
}
};
main()
{
ifstream cin("arbint.in");
ofstream cout("arbint.out");
int n,q;
cin>>n>>q;
vector<int>a(n);
for(auto &c:a)cin>>c;
AINT_MAX<int> tree(a);
while(q--)
{
int tt,a,b;
cin>>tt>>a>>b;
if(tt)
{
tree.update(a-1,b);
}
else
{
cout<<tree.query(a-1,b-1)<<'\n';
}
}
}