Pagini recente » Cod sursa (job #882836) | Cod sursa (job #1605818) | Cod sursa (job #1482341) | Cod sursa (job #1228249) | Cod sursa (job #2683833)
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("plantatie.in");
ofstream fout("plantatie.out");
int n,m,d[501][501][10],x,y,l,p;
int main()
{
fin>>n>>m;
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++)
{
d[i][j][k]=max(d[i][j][k-1],max(d[i+(1<<(k-1))][j][k-1],max(d[i][j+(1<<(k-1))][k-1],d[i+(1<<(k-1))][j+(1<<(k-1))][k-1])));
}
}
}
for(int i=1;i<=m;i++)
{
fin>>x>>y>>l;
p=log2(l);
fout<<max(d[x][y][p],max(d[x+l-(1<<p)][y][p],max(d[x][y+l-(1<<p)][p],d[x+l-(1<<p)][y+l-(1<<p)][p])))<<'\n';
}
}