Pagini recente » Cod sursa (job #2894984) | Cod sursa (job #1154600) | Cod sursa (job #687632) | Cod sursa (job #1729643) | Cod sursa (job #2573514)
#include <fstream>
#include <vector>
#define f first
#define s second
using namespace std;
ifstream fin ("arbint.in");
ofstream fout ("arbint.out");
pair< pair< int, int >, int >A[ 265000 ];
int N, M, i, v[ 100005 ], cer, a, b, MAX;
void construire( int nod, int st, int dr )
{
int mij;
A[ nod ].f.f = st;
A[ nod ].f.s = dr;
if ( st == dr )
{
A[ nod ].s = v[ st ];
}
else
{
mij = ( st + dr ) / 2;
construire( 2 * nod, st, mij );
construire( 2 * nod + 1, mij + 1, dr );
A[ nod ].s = max( A[ 2 * nod ].s, A[ 2 * nod + 1 ].s );
}
}
void maxx( int nod )
{
int st, dr, mij;
st = A[ nod ].f.f;
dr = A[ nod ].f.s;
if ( a <= st && dr <= b )
{
MAX = max( MAX, A[ nod ].s );
}
else
{
mij = ( st + dr ) / 2;
if ( mij >= a )
{
maxx( 2 * nod );
}
if ( mij + 1 <= b )
{
maxx( 2 * nod + 1 );
}
}
}
void inloc( int nod )
{
int st, dr, mij;
st = A[ nod ].f.f;
dr = A[ nod ].f.s;
mij = ( st + dr ) / 2;
if ( st == dr )
{
v[ a ] = b;
A[ nod ].s = b;
}
else if ( a <= mij )
{
inloc( 2 * nod );
A[ nod ].s = max( A[ 2 * nod ].s, A[ 2 * nod + 1 ].s );
}
else
{
inloc( 2 * nod + 1 );
A[ nod ].s = max( A[ 2 * nod ].s, A[ 2 * nod + 1 ].s );
}
}
int main()
{
fin >> N >> M;
for ( i = 1; i <= N; i++ )
{
fin >> v[ i ];
}
construire( 1, 1, N );
for ( i = 1; i <= M; i++ )
{
fin >> cer >> a >> b;
if ( cer == 0 )
{
MAX = 0;
maxx( 1 );
fout << MAX << '\n';
}
else if ( cer == 1 )
{
inloc( 1 );
}
}
}