Pagini recente » Cod sursa (job #1993808) | Cod sursa (job #2013510) | Cod sursa (job #2340351) | Cod sursa (job #1642670) | Cod sursa (job #2569708)
#include <iostream>
#include <fstream>
#define NMAX 100000
using namespace std;
ifstream f("arbint.in");
ofstream g("arbint.out");
int n, q, v[4*NMAX+10], aint[4*NMAX+10];
void build()
{ for(int i=n; i<2*n; i++) aint[i] = v[i-n+1];
for(int i=n-1; i; i--) aint[i] = max(aint[2*i], aint[2*i+1]);
}
int query(int nod, int stnod, int drnod, int stq, int drq)
{ if(stq <= stnod && drnod <= drq) return aint[nod];
int sum = (stnod + drnod) / 2, maxi = 0;
if(stq <= sum) maxi = max(maxi, query(nod*2, stnod, sum, stq, drq));
if(drq > sum) maxi = max(maxi, query(nod*2+1, sum+1, drnod, stq, drq));
return maxi;
}
void update(int val, int poz)
{ poz = poz + n - 1;
aint[poz] = val;
poz /= 2;
while(poz)
{ aint[poz] = max(aint[2*poz], aint[2*poz+1]);
poz /= 2;
}
}
int main()
{
f >> n >> q;
for(int i=1; i<=n; i++) f >> v[i];
if((n & (n-1)) != 0)
{ int maxBit = 0;
while((1 << maxBit) < n) maxBit++;
n = (1 << maxBit);
}
build();
while(q--)
{ int type, a, b;
f >> type >> a >> b;
if(!type) g << query(1, 1, n, a, b) << '\n';
else update(b, a);
}
return 0;
}