Pagini recente » Cod sursa (job #1151119) | Cod sursa (job #1768600) | Cod sursa (job #261239) | Cod sursa (job #1499739) | Cod sursa (job #2859582)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("plantatie.in");
ofstream fout ("plantatie.out");
int n,m,i,j,d[501][501][11],k,lat,x,y,l,p,xx,yy;
int main()
{
fin>>n>>m;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
fin>>d[i][j][0];
for (k=1;(1<<k)<=n;k++)
for (i=1;i+(1<<k)-1<=n;i++)
for (j=1;j+(1<<k)-1<=n;j++)
{
lat=1<<(k-1);
d[i][j][k]=max(max(d[i][j][k-1],d[i+lat][j+lat][k-1]),max(d[i+lat][j][k-1],d[i][j+lat][k-1]));
}
for (i=1;i<=m;i++)
{
fin>>x>>y>>l;
p=log2(l);
xx=x+l-1;
yy=y+l-1;
fout<<max(max(d[x][y][p],d[xx-(1<<p)+1][yy-(1<<p)+1][p]),max(d[xx-(1<<p)+1][y][p],d[x][yy-(1<<p)+1][p]))<<'\n';
}
return 0;
}