Pagini recente » Cod sursa (job #3270714) | Cod sursa (job #3217025) | Cod sursa (job #2753467) | Cod sursa (job #30263) | Cod sursa (job #2476547)
#include <bits/stdc++.h>
using namespace std;
ifstream f("plantatie.in");
ofstream g("plantatie.out");
int n,m,d[510][510][15],a,b,c;
int main()
{
f>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)f>>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++)
{
int max1=max(d[i][j][k-1],d[i][j+(1<<(k-1))][k-1]);
int max2=max(d[i+(1<<(k-1))][j][k-1],d[i+(1<<(k-1))][j+(1<<(k-1))][k-1]);
d[i][j][k]=max(max1,max2);
}
// g<<d[1][1][2]<<'\n';
for(int i=1;i<=m;i++)
{
f>>a>>b>>c;
int x=log2(c);
int j11=b+c-1;
int i11=a+c-1;
int max1=max(d[a][b][x],d[a][j11-(1<<x)+1][x]);
int max2=max(d[i11-(1<<x)+1][b][x],d[i11-(1<<x)+1][j11-(1<<x)+1][x]);
g<<max(max1,max2)<<'\n';
}
return 0;
}