Pagini recente » Cod sursa (job #2645525) | Cod sursa (job #2204025) | Cod sursa (job #2008012) | Cod sursa (job #817087) | Cod sursa (job #2717526)
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
ifstream f("plantatie.in");
ofstream g("plantatie.out");
const int Max = 501;
void nos()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int n,q;
int rmq[Max][32][Max];
void read()
{
f>>n>>q;
int i,j;
for(i=0; i<n; i++)
for(j=0; j<n; j++)
f>>rmq[i][0][j];
}
int mxi;
int ans;
void solve()
{
int i,j,which;
mxi = log2(n);
for(which=0; which<n; which++)
for(i = 1; i<=mxi; ++i)
for(j=0; j + (1<<i) - 1 < n; ++j)
rmq[which][i][j] = max(rmq[which][i-1][j], rmq[which][i-1][j + (1 << (i-1))]);
while(q--)
{
int xs,ys,dim;
f>>xs>>ys>>dim;
--xs,--ys,ans = 0;
int half_log = log2(dim);
for(int j = xs; j<=xs + dim - 1; ++j)
ans = max(ans,max(rmq[j][half_log][ys], rmq[j][half_log][ys + dim - (1<<half_log)]));
g<<ans<<'\n';
}
}
void restart()
{
}
int32_t main()
{
//nos();
read();
solve();
restart();
return 0;
}