Pagini recente » Cod sursa (job #2657283) | Cod sursa (job #2252800) | Cod sursa (job #1388070) | Cod sursa (job #709358) | Cod sursa (job #3227907)
#include <fstream>
using namespace std;
ifstream fin("plantatie.in");
ofstream fout("plantatie.out");
int v[20][500][500];
int e[500];
int main()
{
int n, m, i, i2, j2, j, exp, p, lat, len, x, y;
fin>>n>>m;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
fin>>v[0][i][j];
}
}
for(p=1,lat=2; lat<=n; p++, lat*=2)
{
for(i=1;i<=n-lat+1;i++)
{
for(j=1;j<=n-lat+1;j++)
{
i2=i+(lat/2);
j2=j+(lat/2);
v[p][i][j]=max(max(v[p-1][i][j], v[p-1][i2][j]), max(v[p-1][i][j2], v[p-1][i2][j2]));
}
}
}
e[1]=0;
for(i=2;i<=n;i++)
{
e[i]=1+e[i/2];
}
for(i=1;i<=m;i++)
{
fin>>x>>y>>lat;
exp=e[lat];
len=(1<<exp);
i2=x+lat-len;
j2=y+lat-len;
fout<<max(max(v[exp][x][y], v[exp][i2][y]), max(v[exp][x][j2], v[exp][i2][j2]))<<"\n";
}
}