Pagini recente » Cod sursa (job #2718829) | Cod sursa (job #2299095) | Cod sursa (job #919785) | Cod sursa (job #1723109) | Cod sursa (job #1304562)
#include <cstdio>
#include <fstream>
#define nmax 505
using namespace std;
ifstream f("plantatie.in");
ofstream g("plantatie.out");
int n,m;
int v[10][nmax][nmax];
int lg[505],log,put,lat,lmax,cmax;
int main()
{
int i,j,l,c;
f>>n>>m;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
f>>v[0][i][j];
for (l=1;l<=9;l++)
{put=1<<(l-1);
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
v[l][i][j]=max(max(v[l-1][i][j],v[l-1][i+put][j]),max(v[l-1][i][j+put],v[l-1][i+put][j+put]));}
lg[0]=-1;
for (i=1;i<=500;i++)
lg[i]=lg[i>>1]+1;
while (m) {
f>>l>>c>>lat;
log=lg[lat];
put=1<<log;
lmax=l+lat-1;
cmax=c+lat-1;
g<<max(max(v[log][l][c],v[log][lmax-put+1][c]),max(v[log][l][cmax-put+1],v[log][lmax-put+1][cmax-put+1]))<<'\n';
m--;
}
return 0;}