Pagini recente » Cod sursa (job #904828) | Cod sursa (job #1739956) | Cod sursa (job #610925) | Cod sursa (job #1950138) | Cod sursa (job #1216768)
#include <fstream>
#define rint register int
const char IN [ ] = "plantatie.in" ;
const char OUT [ ] = "plantatie.out" ;
const int LOGMAX = 20 ;
const int MAX = 520 ;
using namespace std;
ifstream fin ( IN ) ;
ofstream fout ( OUT ) ;
int R [ MAX ] [ MAX ] [ LOGMAX ] , log [ MAX ] ;
int main( )
{
int n , m ;
fin >> n >> m ;
for ( rint i = 1 ; i <= n ; ++ i )
for ( rint j = 1 ; j <= n ; ++ j )
fin >> R [ i ] [ j ] [ 0 ] ;
log [ 1 ] = 0 ;
for ( rint i = 2 ; i <= n ; ++ i )
log [ i ] = log [ i >> 1 ] + 1 ;
for ( rint k = 1 ; k <= log [ n ] ; ++ k )
for ( rint i = 1 ; i <= n - ( 1 << k ) + 1 ; ++ i )
for ( rint j = 1 ; j <= n - ( 1 << k ) + 1 ; ++ j )
R [ i ] [ j ] [ k ] = max ( R [ i ] [ j ] [ k - 1 ] ,
max ( R [ i + ( 1 << (k-1) ) ] [ j ] [ k - 1 ] ,
max ( R [ i + ( 1 << (k-1) ) ] [ j + ( 1 << (k-1) ) ] [ k - 1 ] , R [ i ] [ j + ( 1 << (k-1) ) ] [ k - 1 ] )
)
);
while ( m -- )
{
int x ,y , z ;
fin >> x >> y >> z ;
int t = log [ z ] ;
fout << max ( R [ x ] [ y ] [ t ] ,
max ( R[ x ] [ y + z - ( 1 << t ) ][ t ] ,
max( R [ x + z - ( 1 << t ) ] [ y ] [ t ] , R [ x + z - ( 1 << t ) ] [ y + z - ( 1 << t ) ] [ t ] )
)
)
<< '\n' ;
}
return 0;
}