Pagini recente » Cod sursa (job #2938474) | Cod sursa (job #569803) | Cod sursa (job #348298) | Cod sursa (job #3351804) | Cod sursa (job #3344766)
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
ifstream f("plantatie.in");
ofstream g("plantatie.out");
int n,d[501][501][10],m;
int e[501];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
f>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
f>>d[i][j][0];
for(int p=1;(1<<p)<=n;p++)
for(int i1=1;i1<=n-(1<<p)+1;i1++)
for(int j1=1;j1<=n-(1<<p)+1;j1++)
{
int i2=i1+(1<<p-1);
int j2=j1+(1<<p-1);
d[i1][j1][p]=max({d[i1][j1][p-1],d[i1][j2][p-1],d[i2][j1][p-1],d[i2][j2][p-1]});
}
while(m--)
{
int i1,j1,lung;
f>>i1>>j1>>lung;
int p=log2(lung);
int i2=i1+lung-(1<<p);
int j2=j1+lung-(1<<p);
g<<max({d[i1][j1][p],d[i1][j2][p],d[i2][j1][p],d [i2][j2][p]})<<'\n';
}
return 0;
}