Pagini recente » Cod sursa (job #110073) | Cod sursa (job #397439) | Cod sursa (job #2597420) | Cod sursa (job #110653)
Cod sursa(job #110653)
#include <stdio.h>
int i,j,k,n,m,l,a[800][800][11],p,max;
int maxim(int a, int b)
{
if (a>b) return a;
else return b;
}
int main()
{
freopen("plantatie.in","r",stdin);
freopen("plantatie.out","w",stdout);
scanf("%d %d",&n,&m);
for (i=1;i<=n;++i)
for (j=1;j<=n;++j)
scanf("%d ",&a[i][j][0]);
p=0;
while ((1<<p) <= n) p++;
for (k=1;k<=p;++k)
for (i=1;i<=n;++i)
for (j=1;j<=n;++j)
{
a[i][j][k]=maxim(a[i][j][k-1],a[i][j+(1<<(k-1))][k-1]);
a[i][j][k]=maxim(a[i][j][k],a[i+(1<<(k-1))][j+(1<<(k-1))][k-1]);
a[i][j][k]=maxim(a[i][j][k],a[i+(1<<(k-1))][j][k-1]);
}
for (;m>0;--m)
{
scanf("%d %d %d",&i,&j,&k);
p=0;
while ((1<<p) <= k) p++;
--p;
// printf("%d\n",p);
max=maxim(a[i][j][p],a[i][j+k-(1<<p)][p]);
max=maxim(max,a[i+k-(1<<p)][j][p]);
max=maxim(max,a[i+k-(1<<p)][j+k-(1<<p)][p]);
printf("%d\n",max);
}
return 0;
}