Pagini recente » Cod sursa (job #2691559) | Cod sursa (job #1950684) | Cod sursa (job #2459670) | Cod sursa (job #3236745) | Cod sursa (job #3161447)
#include <fstream>
using namespace std;
ifstream cin("plantatie.in");
ofstream cout("plantatie.out");
int n,m,i1,i2,j1,i,j,j2,lat,L,len,k,r[10][502][502],E[502];
int main()
{
cin>>n>>m;
for ( i=1; i<=n; i++)
for ( j=1; j<=n; j++)
cin>>r[0][i][j];
for (int p=1,lat=2; lat<=n; p++,lat*=2)
for ( i1=1; i1<=n-lat+1; i1++)
for ( j1=1; j1<=n-lat+1; j1++)
{
i2=i1+(lat>>1);
j2=j1+(lat>>1);
r[p][i1][j1] = max(max(r[p-1][i1][j1],r[p-1][i2][j1]),max(r[p-1][i1][j2],r[p-1][i2][j2]));
}
E[1]= 0;
for ( i=2; i<=n; i++)
E[i] = 1 + E[i/2];
while(m--)
{
cin>>i1>>j1>>L;
k = E[L];
len = (1<<k);
i2 = i1+L-len;
j2 = j1+L-len;
cout<<max(max(r[k][i1][j1],r[k][i1][j2]),max(r[k][i2][j1],r[k][i2][j2]))<<"\n";
}
return 0;
}