Pagini recente » Cod sursa (job #550083) | Cod sursa (job #1421949) | Cod sursa (job #3150628) | Cod sursa (job #1152491) | Cod sursa (job #1899264)
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int n, m, b, x, y, s;
vector <pair <int, vector <int> > > a; // .first max pe .second
int main()
{
ifstream cin ("arbint.in" );
ofstream cout("arbint.out");
cin >> n >> m;
s = sqrt(n);
a.resize(s + 1);
for (int i = 0; i < n; i++)
{
cin >> 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++)
{
cin >> 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
iterator <pair <int, vector <int> > > it = a[x / s].second.end();
if (x / s == y / s) a[x / s].second.begin() + (y % s);
else it = a[x / s].second.end();
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) )) );
for (int i = 1 + x / s; i < y / s; i++) t = max(t, a[i].first);
for (int i = 0; i < a.size(); i++)
for (int j = 0; j < a[i].second.size(); j++)
cout << a[i].second[j] << ' ';
cout << '\n';
cout << x << ' ' << y << ' ' << t << '\n';
}
}
return 0;
}