Pagini recente » Cod sursa (job #2743805) | Cod sursa (job #2821214) | Cod sursa (job #295069) | Cod sursa (job #443206) | Cod sursa (job #1810440)
#include <bits/stdc++.h>
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
vector<int> v;
int n, m;
void read()
{
f >> n >> m;
for(int i=0, x; i<n; ++i)
{
f >> x; v.push_back(x);
}
}
void update(int poz, const int val, vector<int> &buf){
buf[poz+=n] = val;
for(poz /= 2; poz; poz /= 2)
{
buf[poz] = max(buf[2*poz], buf[2*poz+1]);
}
}
int query(int st, int dr, vector<int> &buf){
int rez = buf[st+=n];
for(dr += n+1; st < dr; st /= 2, dr /= 2){
if(st%2) rez = max(rez, buf[st++]);
if(dr%2) rez = max(rez, buf[--dr]); }
return rez; }
void out()
{
vector <int> buf(2*n);
copy(v.begin(),v.end(), buf.begin()+n);
for(int i = n-1; i > 0; --i)
{
buf[i] = max(buf[2*i], buf[2*i+1]);
}
for(int i=0; i<2*n; ++i) cout<<buf[i]<<" ";
for(int t, a, b; m--; )
{
f >> t >> a >> b;
if(t == 0) g << query(a-1, b-1, buf) << '\n';
else update(a-1, b, buf);
}
f.close();
g.close();
}
int main()
{
read();
out();
return 0;
}