Pagini recente » Cod sursa (job #87181) | Cod sursa (job #2048215) | Rating Laszlofi Zoltan-Yoda (fruits_not_here) | Cod sursa (job #2465025) | Cod sursa (job #2683828)
#include <bits/stdc++.h>
using namespace std;
ifstream f("plantatie.in");
ofstream g("plantatie.out");
int d[505][505][10],n,i,j,m,lg,l,x,y,mx,col;
int main()
{
f>>n>>m;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++) f>>d[i][j][0];
for(i=1;i<=n;i++)
for(l=1;(1<<l)<=n;l++)
for(j=1;j<=n;j++)
{
d[i][j][l]=max(d[i][j][l-1],d[i][j+(1<<(l-1))][l-1]);
}
for(i=1;i<=m;i++)
{
f>>x>>y>>l;
lg=log2(l);
col=y+l-1;
mx=0;
for(j=x;j<=x+l-1;j++)
{
mx=max(mx,max(d[j][y][lg],d[j][col-(1<<lg)+1][lg]));
}
g<<mx<<'\n';
}
return 0;
}