Cod sursa(job #3344766)

Utilizator jarnea_justinjarnea justin ioan jarnea_justin Data 5 martie 2026 16:30:22
Problema Plantatie Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.87 kb
#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;
}