Pagini recente » Cod sursa (job #3155749) | Cod sursa (job #2965019) | Cod sursa (job #2660920) | Cod sursa (job #1691212) | Cod sursa (job #3127855)
#include <bits/stdc++.h>
int rmq[501][501][10], v[501][501];
std::ifstream fin("plantatie.in");
std::ofstream fout("plantatie.out");
int main()
{
auto start = std::chrono::high_resolution_clock::now();
int n, m, s, max1, max2, temp;
fin >> n >> m;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
fin >> s;
v[i][j] = s;
rmq[i][j][0] = v[i][j];
}
}
for(int length = 1; length <= (int)log2(n); ++length)
{
for(int i = 1; i + (1 << length)-1 <= n; ++i)
{
for(int j = 1; j + (1 << length)-1 <= n; ++j)
{
temp = 1 << (length-1);
max1 = std::max(rmq[i][j][length-1], rmq[i][j + temp][length-1]);
max2 = std::max(rmq[i+temp][j][length-1], rmq[i + temp][j + temp][length-1]);
rmq[i][j][length] = std::max(max1, max2);
}
}
}
int x, y, z, k;
for(int i = 1; i <= m; ++i)
{
fin >> x >> y >> z;
k = (int)log2(z);
temp = 1 << k;
max1 = std::max(rmq[x][y][k], rmq[x][y + z - temp][k]);
max2 = std::max(rmq[x + z - temp][y][k], rmq[x + z - temp][y + z - temp][k]);
fout << std::max(max1, max2) << '\n';
}
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << duration.count() << '\n';
}