Pagini recente » Cod sursa (job #1868385) | Cod sursa (job #1997687) | Cod sursa (job #530239) | Cod sursa (job #385709) | Cod sursa (job #2902169)
#include <iostream>
#include <fstream>
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 <= n; i++)
for(int j = 1; j <= 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 = 0;
fin >> i >> j >> l;
while((1<<pow2)<<1 <= l)
pow2++;
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+k-(1<<pow2)][pow2])) << '\n';
}
}