Cod sursa(job #2485533)

Utilizator DavvDrgDavid Dragostin DavvDrg Data 1 noiembrie 2019 18:41:53
Problema Plantatie Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <bits/stdc++.h>

using namespace std;
ifstream in("plantatie.in");
ofstream out("plantatie.out");
int n,m,d[510][510][15],a,b,c,max1,max2;
int main()
{
    int i,j,k;
    in>>n>>m;
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            in>>d[i][j][0];
    for(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++)
            {
            max1=max(d[i][j][k-1],d[i][j+(1<<(k-1))][k-1]);
            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);
            }
    for(i=1;i<=m;i++)
    {
        in>>a>>b>>c;
        int x=log2(c);
        int j11=b+c-1;
        int i11=a+c-1;
        max1=max(d[a][b][x],d[a][j11-(1<<x)+1][x]);
        max2=max(d[i11-(1<<x)+1][b][x],d[i11-(1<<x)+1][j11-(1<<x)+1][x]);
        out<<max(max1,max2)<<'\n';
    }
    return 0;
}