Pagini recente » Cod sursa (job #99126) | Cod sursa (job #1911521) | Cod sursa (job #1065999) | Cod sursa (job #1119426) | Cod sursa (job #2291357)
#include <cstdio>
#include <fstream>
using namespace std;
inline void f();
int n,m,i,j,d[510][510][20],pow,x1,x2,y1,y2,lat,maxim,p,k,log,max1,max2,l[510];
int main() {
f();
return 0;
}
inline void f() {
freopen("plantatie.in","r",stdin);
freopen("plantatie.out","w",stdout);
scanf("%d%d",&n,&m);
for (i=2;i<=n;i++)
l[i]=1+l[i/2];
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
scanf("%d",&d[i][j][0]);
for (k=1;k<=l[n];k++) {
pow=(1<<(k-1));
for (i=1;i<=n-pow;i++) {
for (j=1;j<=n-pow;j++) {
max1=max(d[i][j][k-1],d[i+pow][j][k-1]);
max2=max(d[i][j+pow][k-1],d[i+pow][j+pow][k-1]);
d[i][j][k]=max(max1,max2);
}
}
}
for (i=1;i<=m;i++) {
scanf("%d%d%d",&x1,&y1,&lat);
x2=x1+lat-1, y2=y1+lat-1;
log=l[lat];
p=(1<<log);
max1=max(d[x1][y1][log],d[x2-p+1][y1][log]);
max2=max(d[x1][y2-p+1][log],d[x2-p+1][y2-p+1][log]);
maxim=max(max1,max2);
printf("%d\n",maxim);
}
return;
}