Pagini recente » Cod sursa (job #2341897) | Cod sursa (job #842193) | Cod sursa (job #452081) | Cod sursa (job #112199) | Cod sursa (job #1704707)
//package arbint;
import java.util.*;
import java.io.*;
/***
*
* @author Patrick
*
*/
public class Main {
public static int [ ] arb = new int [ 700999 ] ;
public static int sol ;
public static void main(String[] args) throws FileNotFoundException {
Scanner scanner = new Scanner(new BufferedInputStream(new FileInputStream("arbint.in")));
PrintStream output = new PrintStream(new FileOutputStream("arbint.out"));
int N = scanner.nextInt() ;
int M = scanner.nextInt() ;
for ( int i = 1 ; i <= N ; ++ i ) {
int X = scanner.nextInt() ;
update ( 1 , 1 , N , i , X ) ;
}
for ( int i = 1 ; i <= M ; ++ i ) {
int Tip = scanner.nextInt() ;
if ( Tip == 1 ) {
int X = scanner.nextInt() ;
int Y = scanner.nextInt() ;
update ( 1 , 1 , N , X , Y ) ;
}
else {
int X = scanner.nextInt() ;
int Y = scanner.nextInt() ;
sol = 0 ;
query ( 1 , 1 , N , X , Y ) ;
output.print( sol );
output.print( "\n" );
}
}
}
public static void query ( int nod , int st , int dr , int a , int b )
{
//System.out.println( "a intrat" );
//System.out.println( nod );
if ( a <= st && dr <= b ) {
sol = Math.max( sol , arb [ nod ] ) ;
return ;
}
int mij = ( st + dr ) / 2 ;
if ( a <= mij ) {
query ( nod * 2 , st , mij , a , b ) ;
}
if ( b > mij ) {
query ( nod * 2 + 1 , mij + 1 , dr , a , b ) ;
}
return ;
}
public static void update ( int nod , int st , int dr , int pos , int val )
{
if ( st == dr ) {
arb [ nod ] = val ;
return ;
}
int mij = ( st + dr ) / 2 ;
if ( pos <= mij ) {
update ( nod * 2 , st , mij , pos , val ) ;
}
else {
update ( nod * 2 + 1 , mij + 1 , dr , pos , val ) ;
}
arb [ nod ] = Math.max ( arb [ nod * 2 ] , arb [ nod * 2 + 1 ] ) ;
}
}