Pagini recente » Cod sursa (job #1335294) | Cod sursa (job #1250466) | Cod sursa (job #2460554) | Cod sursa (job #3278440) | Cod sursa (job #3297084)
#include <bit>
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
using namespace std;
int plantatie[501][501][10];
using namespace std;
int main() {
ifstream cin("plantatie.in");
ofstream cout("plantatie.out");
int n, m; cin >> n >> m;
int log2n = log2(n) + 1;
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
cin >> plantatie[i][j][0];
}
}
for(int p = 1; p < log2n; p++) {
int offs = 1 << p - 1;
for(int i = 0; i < n - (1 << p - 1); i++) {
for(int j = 0; j < n - (1 << p - 1); j++) {
plantatie[i][j][p] = max(
max(plantatie[i][j][p-1], plantatie[i + offs][j + (1 << p - 1)][p - 1]),
max(plantatie[i][j + offs][p - 1], plantatie[i + offs][j][p - 1])
);
}
}
}
while(m-- > 0) {
int i, j, l; cin >> i >> j >> l;
i--;j--;
int p = log2(l);
int offs = l - (1 << p);
int res = max(
max( plantatie[i][j][p], plantatie[i + offs][j + offs][p]),
max( plantatie[i + offs][j][p], plantatie[i][j + offs][p])
);
cout << res << "\n";
}
::cin >> n;
}