Pagini recente » Statistici Macho Nacho (Cryptic) | Cod sursa (job #1531645) | Profil mateisirghe | Monitorul de evaluare | Cod sursa (job #2474856)
#include<bits/stdc++.h>
#define N 100010
#define L nod<<1
#define R L|1
using namespace std;
int n,q;
int a[N];
int h[4*N];
int pos,val,l,r;
void update(int st, int dr, int nod) {
if (st==dr) {
h[nod]=val;
return;
}
int mid=(st+dr)>>1;
if (pos<=mid) update(st,mid,L);
else update(mid+1,dr,R);
h[nod]=max(h[L],h[R]);
}
int query(int st, int dr, int nod) {
if (l<=st && dr<=r) {
return h[nod];
}
int mid=(st+dr)>>1;
int left=0,right=0;
if (l<=mid) left=query(st,mid,L);
if (r>mid) right=query(mid+1,dr,R);
return max(left, right);
}
void build(int st, int dr, int nod) {
if (st==dr) {
h[nod]=a[st];
return ;
}
int mid=(st+dr)>>1;
build(st,mid,L);
build(mid+1,dr,R);
h[nod]=max(h[L],h[R]);
}
int main() {
ifstream cin("arbint.in");
ofstream cout("arbint.out");
cin>>n>>q;
for (int i=1; i<=n; i++) {
cin>>a[i];
}
build(1,n,1);
while (q--) {
int c,a,b; cin>>c>>a>>b;
if (!c) {
l = a, r=b;
cout<<query(1,n,1)<<'\n';
} else {
pos = a; val=b;
update(1,n,1);
}
}
return 0;
}