Pagini recente » Cod sursa (job #932201) | Cod sursa (job #52133) | Cod sursa (job #2991227) | Cod sursa (job #3284462) | Cod sursa (job #2985568)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("plantatie.in");
ofstream fout("plantatie.out");
int d[501][501][10],n,q,x,y,k,l,nr;
int main()
{
fin>>n>>q;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
fin>>d[i][j][0];
}
}
for(int k=1;(1<<k)<=n;k++)
{
for(int i=1;i+(1<<k)-1<=n;i++)
{
for(int j=1;j+(1<<k)-1<=n;j++)
{
l=k-1;
d[i][j][k]=max(d[i][j][l],max(d[i+(1<<l)][j][l],max(d[i][j+(1<<l)][l],d[i+(1<<l)][j+(1<<l)][l])));
}
}
}
for(int i=1;i<=q;i++)
{
fin>>x>>y>>k;
l=log2(k);
nr=max(d[x][y][l],max(d[x+k-(1<<l)][y][l],max(d[x][y+k-(1<<l)][l],d[x+k-(1<<l)][y+k-(1<<l)][l])));
fout<<nr<<'\n';
}
return 0;
}