Pagini recente » Cod sursa (job #1511879) | Cod sursa (job #1539891) | Cod sursa (job #1792314) | Cod sursa (job #2561344) | Cod sursa (job #387660)
Cod sursa(job #387660)
// bit_trees.cpp
//
// Copyright 2010 SpeeDemon <virtualdemon@ubuntu>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
#include <fstream>
#define Nmax 100001
/*
*
*/
using namespace std;
int N;
int tree[Nmax], v[Nmax];
inline int max( int x, int y )
{
if( v[x] > v[y] )
return x;
return y;
}
int Query( int x, int y )
{int maxim=y, i, j;
for( i=x; i <= y; ++i )
{
maxim=max( maxim, i );
}
return maxim;
}
void Update( int x )
{int z;
for( z=x; z <= N; z+=( z & -z ) )
if( x == tree[z] )
{
tree[z]=max( tree[z] , Query( z-( z & -z ), z-1 ) );
}
else tree[z]=max( tree[z], x );
}
int main()
{int n, m, i, x, y, z;
ifstream in("arbint.in");
in>>n>>m;
for( i=1; i <= n; ++i )
{
in>>v[i];
Update( i );
}
ofstream out("arbint.out");
for( i=0; i < m; ++i )
{
in>>x>>y>>z;
if( 0 == x )
out<<v[ Query( y, z ) ]<<'\n';
else {
v[y]=z;
Update( y );
}
}
return 0;
}