Cod sursa(job #2503881)

Utilizator AnduebossAlexandru Ariton Andueboss Data 3 decembrie 2019 21:17:57
Problema Plantatie Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.16 kb
//
//  main.cpp
//  citire
//
//  Created by Andu Andu on 03/12/2019.
//  Copyright © 2019 Andu Andu. All rights reserved.
//

#include <iostream>
#include <fstream>
#define D 503
#define Q 75003
#define log_2 10
using namespace std;
ifstream f("file.in");
ofstream g("file.out");
int a[log_2][D][D];
int main()
{
    int n,m,i,j,p2,k,c1,c2,c3,c4;
    f>>n>>m;
    /// citire
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++) {
            f>>a[0][i][j];
            
        }
    /// completare
    for(p2=1;(1<<p2)<=n;p2++)///tabelul curent
        for(i=1;i<=n-(1<<p2)+1;i++)///linia
            for(j=1;j<=n-(1<<p2)+1;j++)///coloana
            {
                c1=a[p2-1][i][j];
                c2=a[p2-1][i+(1<<(p2-1))][j];
                c3=a[p2-1][i+(1<<(p2-1))][j+(1<<(p2-1))];
                c4=a[p2-1][i][j+(1<<(p2-1))];
                a[p2][i][j]=max(max(c1,c2),max(c3,c4));
                k++;
            }
 
    ///raspunderea la intrebari
    for(int t=1;t<=m;t++)
    {
        f>>i>>j>>k;
        p2=0;
        while((1<<(p2+1))<=k)p2++;
        g<<max(max(a[p2][i][j],a[p2][i+k-(1<<p2)][j]),max(a[p2][i+k-(1<<p2)][j+k-(1<<p2)],a[p2][i][j+k-(1<<p2)]))<<"\n";
    }
}