Pagini recente » Cod sursa (job #314615) | Cod sursa (job #2585141) | Cod sursa (job #2270765) | Cod sursa (job #1578611) | Cod sursa (job #1673987)
#include <fstream>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
const int nmax = 1000000;
int n, adi[nmax], p = 1, m;
int query(int ind, int st, int dr, int stc, int drc){
int mij;
if(st == stc && dr == drc){
return adi[ind];
}
else {
mij = (st + dr) / 2;
if(stc <= mij && drc > mij){
int x1, x2;
x1 = query( 2 * ind, st, mij, stc, mij);
x2 = query( 2 * ind + 1, mij + 1, dr, mij + 1, drc);
return max( x1, x2);
}
else if(stc <= mij){
return query( 2 * ind, st, mij, stc, drc );
}
else return query( 2 * ind + 1, mij + 1, dr, stc, drc );
}
}
void update(int poz, int val){
adi[poz] = val;
poz /= 2;
while(poz){
adi[poz] = max( adi[2 * poz], adi[2 * poz + 1] );
poz /= 2;
}
}
int main()
{
f>>n>>m;
while(p <= n){
p<<=1;
}
for(int i = p; i <= p + n - 1; ++i){
f>>adi[i];
}
for(int i = p - 1; i >= 1; --i){
adi[i] = max( adi[2 * i], adi[2 * i + 1] );
}
for(int i = 1, o, a, b; i <= m; ++i){
f>>o>>a>>b;
if(o == 1){
update(p + a - 1, b);
}
else {
g<<query(1, 1, p, a, b)<<'\n';
}
}
return 0;
}