Pagini recente » Cod sursa (job #2253758) | Cod sursa (job #1285805) | Cod sursa (job #2906814) | Cod sursa (job #157898) | Cod sursa (job #3230344)
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
ifstream f("plantatie.in");
ofstream g("plantatie.out");
int mat [502][502];
int rmq [10][502][502];
int n,q,i,j,k,a,b;
int LOG[502];
int main()
{
f>>n>>q;
for (i=1;i<=n;i++)
for(j=1;j<=n;j++)
{ f>>mat[i][j];
rmq[0][i][j]=mat[i][j];
}
for (i=2;i<=n;i++)LOG[i]=LOG[i/2]+1;
for (i=1;i<=LOG[n];i++)
for (j=1;j<=n;j++)
for (k=1;k<=n;k++)
{ rmq[i][j][k]=max(
rmq[i-1][j][k],
max(
rmq[i-1][j+(1<<(i-1))][k],
max(
rmq[i-1][j+(1<<(i-1))][k+(1<<(i-1))],
rmq[i-1][j][k+(1<<(i-1))]
)
)
);
}
while (q--)
{ f>>a>>b>>k;
j=0;
j=max(rmq[LOG[k]][a][b],rmq[LOG[k]][a+k-(1<<LOG[k])][b]);
j=max(j,rmq[LOG[k]][a+k-(1<<LOG[k])][b+k-(1<<LOG[k])]);
j=max(j,rmq[LOG[k]][a][b+k-(1<<LOG[k])]);
g<<j<<'\n';
}
return 0;
}