Pagini recente » Cod sursa (job #1881229) | Cod sursa (job #120213) | Cod sursa (job #1841641) | Cod sursa (job #2418751) | Cod sursa (job #2616064)
#include <bits/stdc++.h>
using namespace std;
int n,m,i,j,x,k,pas,p,maxim,A[510][510][15];
int main()
{
ifstream fin("plantatie.in");
ofstream fout("plantatie.out");
fin>>n>>m;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
fin>>x;
A[i][j][0]=x;
}
}
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++)
{
maxim=max(A[i][j][k-1], A[i][j+(1<<(k-1))][k-1]);
maxim=max(maxim, A[i+(1<<(k-1))][j][k-1]);
maxim=max(maxim, A[i+(1<<(k-1))][j+(1<<(k-1))][k-1]);
A[i][j][k]=maxim;
}
}
}
for(pas=1;pas<=m;pas++)
{
fin>>i>>j>>k;
p=log2(k);
maxim=max(A[i][j][p], A[i][j+k-(1<<p)][p]);
maxim=max(maxim, A[i+k-(1<<p)][j][p]);
maxim=max(maxim, A[i+k-(1<<p)][j+k-(1<<p)][p]);
fout<<maxim<<'\n';
}
return 0;
}