Pagini recente » Cod sursa (job #500218) | Cod sursa (job #1359082) | Cod sursa (job #1672226) | Cod sursa (job #1499177) | Cod sursa (job #2525213)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("arbint.in");
ofstream fout("arbint.out");
const int NMAX=1e5;
int n,m,a[4*NMAX+66];
int val,poz,x,y,Max;
void Up(int c,int l,int r)
{
if(l==r)
{
a[c]=val;
return;
}
int div=(l+r)/2;
if(poz<=div)
Up(2*c,l,div);
else
Up(2*c+1,div+1,r);
a[c]=max(a[2*c+1],a[2*c]);
}
void Find(int c,int l,int r)
{
if(x<=l and r<=y)
{
if(a[c]>Max)
Max=a[c];
return;
}
int div=(l+r)/2;
if(x<=div)
Find(2*c,l,div);
if(div<y)
Find(2*c+1,div+1,r);
}
int main()
{
fin >> n >> m;
for(int i=1;i<=n;i++)
{
fin >> val;
poz=i;
Up(1,1,n);
}
for(;m;m--)
{
int t;
fin >> t >> x >> y;
if(t%2==0)
{
Max=-1;
Find(1,1,n);
fout << Max << "\n";
}
else
{
poz=x;
val=y;
Up(1,1,n);
}
}
return 0;
}