Pagini recente » Cod sursa (job #529901) | Cod sursa (job #1087563) | Cod sursa (job #2776391) | Cod sursa (job #2325296) | Cod sursa (job #2902181)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("plantatie.in");
ofstream fout("plantatie.out");
int plantatie[505][505][10];
int main()
{
int n, m;
fin >> n >> m;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
fin >> plantatie[i][j][0];
for(int k = 1; (1<<k) <= n; ++k)
for(int i = 1; i + (1<<k) -1 <= n; ++i)
for(int j = 1; j+ (1<<k) -1 <= n; ++j)
plantatie[i][j][k]=max(max(plantatie[i][j][k-1],plantatie[i][j+(1<<(k-1))][k-1]),max(plantatie[i+(1<<(k-1))][j][k-1], plantatie[i+(1<<(k-1))][j+(1<<(k-1))][k-1]));
for(int k = 1; k <= m; ++k)
{
int i, j, l, pow2;
fin >> i >> j >> l;
pow2 = log2(l);
fout << max(max(plantatie[i+l-(1<<pow2)][j][pow2],plantatie[i+l-(1<<pow2)][j+l-(1<<pow2)][pow2]),max(plantatie[i][j][pow2],plantatie[i][j+l-(1<<pow2)][pow2])) << '\n';
}
}