Pagini recente » Cod sursa (job #2619283) | Cod sursa (job #2111027) | Cod sursa (job #2675297) | Cod sursa (job #1213334) | Cod sursa (job #2710343)
#include <bits/stdc++.h>
#define NMAX 505
using namespace std;
ifstream fin("plantatie.in");
ofstream fout("plantatie.out");
int rmq[NMAX][NMAX][10], mat[NMAX][NMAX];
int max(int a, int b, int c, int d){
return (max(a, max(b, max(c, d))));
}
int main()
{
int n, m;
fin >> n >> m;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j){
fin >> mat[i][j];
rmq[i][j][0] = mat[i][j];
}
int mxP = log2(n);
for(int put = 1; put <= mxP; ++put)
for(int i = 1; i <= n - (1 << put) + 1; ++i)
for(int j = 1; j <= n - (1 << put) + 1; ++j)
rmq[i][j][put] = max(rmq[i][j][put - 1],rmq[i + (1 << (put - 1))][j][put - 1], rmq[i][j + (1 << (put - 1))][put - 1], rmq[i + (1 << (put - 1))][j + (1 << (put - 1))][put - 1]);
for(int i = 1; i <= m; ++i){
int x, y, pu;
fin >> x >> y >> pu;
int x2 = x + pu - 1, y2 = y + pu - 1;
int cls = log2(pu);
fout << max(rmq[x][y][cls], rmq[x2 - (1 << (cls)) + 1][y][cls], rmq[x][y2 - (1 << (cls)) + 1][cls], rmq[x2 - (1 << (cls)) + 1][y2 - (1 << (cls)) + 1][cls]) << '\n';
}
return 0;
}