Cod sursa(job #3297476)

Utilizator busoistefanBusoi Radulescu Stefan busoistefan Data 22 mai 2025 17:57:40
Problema Plantatie Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("plantatie.in");
ofstream out("plantatie.out");

int str[1000][1000][22];
int main() {
    int n, m;
    in >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            in>>str[i][j][0];
        }
    }
    for (int p=1;(1<<p)<n;p++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                str[i][j][p]=max(max(str[i][j][p-1],              str[i+(1<<(p-1))][j][p-1]),
                                 max(str[i][j+(1<<(p-1))][p-1],str[i+(1<<(p-1))][j+(1<<(p-1))][p-1]));
            }
        }
    }
    for (int i = 1; i <= m; i++) {
        int x,y,l;
        in>>x>>y>>l;
        int p=0;
        while ((1<<(p+1))<l) {
            p++;
        }
        out<<max(max(str[x+l-(1<<(p))][y+l-(1<<(p))][p], str[x+l-(1<<(p))][y][p]),
                     max(str[x][y][p],                               str[x][y+l-(1<<(p))][p]))<<'\n';
    }
}