Pagini recente » Cod sursa (job #384160) | Cod sursa (job #354123) | Cod sursa (job #2540410) | Cod sursa (job #806189) | Cod sursa (job #1334216)
#include <cstdio>
#include <iostream>
#define INF 200000000
using namespace std;
FILE *fin = fopen("plantatie.in" ,"r");
FILE *fout= fopen("plantatie.out","w");
int n, m, i, j, k, ok, minim;
int d[1000][1000][10],v[513];
int x, y, z, t, p, pow;
int max(int x, int y, int z, int t){
if(x >= y && x >= z && x >= t) return x;
if(y >= x && y >= z && y >= t) return y;
if(z >= x && z >= y && z >= t) return z;
if(t >= x && t >= y && t >= z) return t;
}
void SetUp(){
fscanf(fin, "%d%d", &n, &m);
for(i = 1; i <= n; i ++)
for(j = 1; j <= n; j ++)
fscanf(fin, "%d", &d[i][j][0]);
for(i = 2; i <= n; i ++)
v[i] = 1 + v[i/2];
for(k = 1; (1<<k) <= n; k ++)
for(i = 1; i <= n; i ++)
for(j = 1; j <= n; j ++){
pow = (1<<(k-1));
d[i][j][k] = max(d[i][j][k-1], d[i+pow][j][k-1], d[i][j+pow][k-1], d[i+pow][j+pow][k-1]);
}
return;
}
void Query(){
for(t = 1; t <= m; t ++){
fscanf(fin, "%d%d%d", &x, &y, &z); p = v[z]; pow = (1<<p);
fprintf(fout, "%d\n", max(d[x][y][p], d[x+z-pow][y][p], d[x][y+z-pow][p], d[x+z-pow][y+z-pow][p]));
}
return;
}
int main(){
SetUp();
Query();
return 0;
}