Pagini recente » Cod sursa (job #1018537) | Cod sursa (job #2775624) | Cod sursa (job #3213168) | Cod sursa (job #2429376) | Cod sursa (job #2621969)
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, l, matrice[503][503][12];
int plantatie[503][503];
ifstream f("plantatie.in");
ofstream g("plantatie.out");
int main() {
f >> n >> m;
for (int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++) {
f >> plantatie[i][j];
matrice[i][j][0] = plantatie[i][j];
}
for (int k = 1; k <= log2(n) + 1; k++)
for(int i = 1; i <= n && i + (1 << k) <= n + 1; i++)
for(int j = 1; j <= n && j +(1 << k) <= n + 1; j++)
{
matrice[i][j][k] = max(matrice[i][j][k - 1], matrice[i + (1 << (k - 1))][j + (1 << (k - 1))][k - 1]);
int max1 = max(matrice[i + (1 << (k - 1))][j][k - 1], matrice[i][j + (1 << (k - 1))][k - 1]);
matrice[i][j][k] = max(matrice[i][j][k], max1);
}
while(m)
{
f >> x >> y >> l;
int poz = log2(l);
int r = max(matrice[x][y][poz], matrice[x + l - (1 << poz)][y][poz]);
int final = max(matrice[x][y + l - (1 << poz)][poz], matrice[x + l - (1 << poz)][y + l - (1 << poz)][poz]);
final = max(final, r);
g << final << '\n';
m--;
}
f.close();
g.close();
return 0;
}