Pagini recente » Cod sursa (job #132199) | Cod sursa (job #3155543) | Cod sursa (job #1414402) | Cod sursa (job #2063610) | Cod sursa (job #3164406)
#include <iostream>
#include <fstream>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
template<typename type>
type lmax(type first){
return first;
}
template<typename type, typename... mtype>
type lmax(type first, mtype... rest){
return max(first, lmax(rest...));
}
int main(){
ifstream fin("plantatie.in");
ofstream fout("plantatie.out");
int lat, nrq; fin>>lat>>nrq;
int rmq[(int)log2(4*lat)][lat][lat];
for(int i=0; i<lat; i++){
for(int j=0; j<lat; j++){
fin>>rmq[0][i][j];
}
}
for(int p=0; (1<<(p+1))<=lat; p++){
for(int i=0; i<lat; i++){
for(int j=0; j<lat; j++){
rmq[p+1][i][j]=rmq[p][i][j];
int i1=i+(1<<(p));
int j1=j+(1<<(p));
if(i1<lat && j1<lat) rmq[p+1][i][j]=lmax(rmq[p][i][j], rmq[p][i1][j], rmq[p][i][j1], rmq[p][i1][j1]);
}
}
}
for(int k=0; k<nrq; k++){
int lin, col, lg; fin>>lin>>col>>lg; lin--; col--;
int exp=(int)log2(lg);
int i=lin+lg-(1<<exp);
int j=col+lg-(1<<exp);
fout<<lmax(rmq[exp][lin][col], rmq[exp][lin][j], rmq[exp][i][col], rmq[exp][i][j])<<endl;
}
return 0;
}