Cod sursa(job #2937642)

Utilizator EasyTnsEasyTns EasyTns Data 10 noiembrie 2022 19:18:20
Problema Plantatie Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.37 kb
#include<fstream>
#include<vector>
#include<algorithm>
//#include<iostream>
using namespace std;
ifstream cin("plantatie.in");
ofstream cout("plantatie.out");
int a[9][502][9][502],E[503];
int x,x1,y,y1,len,len1;
int n,m,k;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        cin>>a[0][i][0][j];

        for(int p=1;(1<<p)<=n;p++)
            for(int j=1;j+(1<<(p-1))<=n;j++)
                a[0][i][p][j]=max(
                        a[0][i][p-1][j],
                        a[0][i][p-1][j+(1<<(p-1))]
                        );
    }
    for(int h=1;(1<<h)<=n;h++)
        for(int i=1;i<=n;i++)
            for(int p=0;(1<<p)<=n;p++)
                for(int j=1;j<=n;j++)
                    a[h][i][p][j]=max(
                            a[h-1][i][p][j],
                            a[h-1][i+(1<<(h-1))][p][j]
                            );

    for(int i=2;i<=n;i++)
        E[i]=1+E[i/2];
for(;m;m--)
{
    int l,l1,l2;
    cin>>l>>l1>>l2;
    x=l;
    y=l1;
    x1=x+l2-1;
    y1=y+l2-1;
    int e1=E[x1-x+1];
    int e2=E[y1-y+1];
    len=(1<<e1);
    len1=(1<<e2);
cout<<max(
        max(
                a[e1][x][e2][y],
                a[e1][x][e2][y1-len1+1]
                ),
                max(
                        a[e1][x1-len+1][e2][y],
                        a[e1][x1-len+1][e2][y1-len1+1]
                        )
        )<<'\n';

}
}