Pagini recente » Cod sursa (job #2037438) | Cod sursa (job #1040082) | Cod sursa (job #1551334) | Cod sursa (job #1145489) | Cod sursa (job #1812129)
/// Problema "Plantatie" - InfoArena
#include <cstdio>
#include <algorithm>
#define in "plantatie.in"
#define out "plantatie.out"
#define NMAX (500 + 7)
#define Log 10
using namespace std;
int N, M, rmq[Log][NMAX][NMAX], X, Y, len;
int query(const int &x, const int &y, const int &Len)
{
int put = 0;
for(; (1<<put) <= Len; ++put);put --;
return max(max(rmq[put][x][y], rmq[put][x][y+Len-(1<<put)]), max(rmq[put][x+Len-(1<<put)][y], rmq[put][x+Len-(1<<put)][y+Len-(1<<put)]));
}
int main()
{
freopen(in, "r", stdin);
freopen(out, "w", stdout);
scanf("%d %d", &N, &M);
for(int i = 1; i<= N; ++i)
{
for(int j = 1; j<= N; ++j)
{
scanf("%d ", &rmq[0][i][j]);
}
}
for(int t = 1; t<= Log-1; ++t)
{
for(int i = 1; i<= N; ++i)
{
if(i + (1<<t) - 1 > N) break;
for(int j = 1; j<= N; ++j)
{
if(j + (1<<t) - 1 > N) break;
rmq[t][i][j] = max(max(rmq[t-1][i][j], rmq[t-1][i+(1<<(t-1))][j]), max(rmq[t-1][i][j+(1<<(t-1))], rmq[t-1][i+(1<<(t-1))][j+(1<<(t-1))]));
}
}
}
for(; M; --M)
{
scanf("%d %d %d", &X, &Y, &len);
printf("%d\n", query(X, Y, len));
}
return 0;
}