Pagini recente » Cod sursa (job #2405619) | Cod sursa (job #771441) | Cod sursa (job #2674692) | Cod sursa (job #1411943) | Cod sursa (job #1899567)
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
//#include <iostream>
using namespace std;
int n, m, b, x, y, s;
vector <pair <int, vector <int> > > a; // .first max pe .second
int main()
{
ifstream fin ("arbint.in" );
ofstream cout("arbint.out");
fin >> n >> m;
s = sqrt(n);
a.resize(s);
for (int i = 0; i < n; i++)
{
fin >> x;
a[i / s].second.push_back(x);
}
for (int i = 0; i < a.size(); i++)
a[i].first = *(max_element(a[i].second.begin(), a[i].second.end() ) );
for (int i = 0; i < m; i++)
{
fin >> b >> x >> y;
x--;
if (!(b)) y--;
if (b)
{ //atribuirea
a[x / s].second[x % s] = y;
a[x / s].first = *(max_element(a[x / s].second.begin(), a[x / s].second.end()));
}
else
{ //afisarea
vector<int>::iterator it;
it = a[x / s].second.end();
if (x / s == y / s) it = a[x / s].second.begin() + (y % s);
int t = *(max_element( a[x / s].second.begin() + (x % s), it));
it = a[y / s].second.begin();
if (x / s == y / s) it = a[y / s].second.begin() + (x % s);
t = max(t, *(max_element( it, a[y / s].second.begin() + (y % s) + 1 )) );
if ((y - x) / s) for (int i = 1 + x / s; i < y / s; i++) t = max(t, a[i].first);
cout << t << '\n';
}
}
return 0;
}