Pagini recente » Rating Nenciu Bianca (nenciu.bianca) | Rating Anicai Denis (deniros14) | Cod sursa (job #1932700) | Monitorul de evaluare | Cod sursa (job #1935960)
#include <fstream>
const int kNMAX = 200020;
int n; // number of elements in the vector
int m; // number of operations applied to the vector
int A[kNMAX]; // the vector
int query(int left, int right)
{
int result = -1;
for ( left += n, right += n; left < right; left /= 2, right /= 2)
{
if (left % 2)
{
result = std::max(result, A[left++]);
}
if (right % 2)
{
result = std::max(result, A[--right]);
}
}
return result;
}
void update(int position, int value)
{
A[position += n] = value;
for (position /= 2; position; position /= 2)
{
A[position] = std::max(A[2*position], A[2*position + 1]);
}
}
int main()
{
std::ifstream fin("arbint.in");
std::ofstream fout("arbint.out");
int i, x, y;
int operationCode;
fin >> n >> m;
for ( i = n+1; i <= 2*n; i++ )
{
fin >> A[i];
}
for ( i = n; i > 0; i--)
{
A[i] = std::max(A[2*i], A[2*i+1]);
}
for (i = 1; i <= m; i++)
{
fin >> operationCode >> x >> y;
if (operationCode == 0)
{
fout << query(x, y+1) << '\n';
}
else
{
update(x, y);
}
}
fin.close();
fout.close();
return 0;
}