Pagini recente » Cod sursa (job #2747440) | Cod sursa (job #316379) | Cod sursa (job #1653097) | Cod sursa (job #1744016) | Cod sursa (job #1838085)
#include <iostream>
#include <cmath>
#include <climits>
using namespace std;
int A[100010];
int B[100005];
int N, M;
int lung_bloc, nr_bloc;
void calcMax(){
int j = 0;
int maxim = 0;
for(int i=0; i<nr_bloc; i++){
maxim = A[j];
for(int k=0; k<lung_bloc; k++){
if(A[j] > maxim)
maxim = A[j];
j++;
}
B[i] = maxim;
}
}
int query(int st, int dr){
int maxim = A[st];
while((st % lung_bloc)!=0 && (st <= dr)){
if(A[st] > maxim)
maxim = A[st];
st++;
}
while(((dr+1)%lung_bloc!=0) && (dr > st)){
if(A[dr] > maxim)
maxim = A[dr];
dr--;
}
int st_bloc = st/lung_bloc;
int dr_bloc = dr/lung_bloc;
if((st % lung_bloc==0) && (dr - st+1) >= lung_bloc )
for(int i=st_bloc; i<=dr_bloc; i++){
if(B[i] > maxim)
maxim = B[i];
}
return maxim;
}
void update_bloc(int pos, int val){
A[pos] = val;
int maxim = 0;
int bloc = pos/lung_bloc;
if(bloc < nr_bloc){
int j = bloc * lung_bloc;
maxim = A[j];
for(int k=0; k<lung_bloc; k++){
if(A[j] > maxim)
maxim = A[j];
j++;
}
B[bloc] = maxim;
}
}
void afis(){
for(int i=0; i<N; i++)
cout << A[i] << " ";
}
int main()
{
freopen("arbint.in","r", stdin);
freopen("arbint.out","w", stdout);
scanf("%d %d", &N, &M);
for(int i=0; i<N; i++)
scanf("%d", &A[i]);
lung_bloc = (int)sqrt(N);
nr_bloc = N/lung_bloc;
calcMax();
int op, a, b;
for(int i=0; i<M; i++){
scanf("%d %d %d", &op, &a, &b);
if(op == 0)
printf("%d", query(a-1, b-1));
else
update_bloc(a-1, b);
if(i !=M-1 && op == 0)
printf("\n");
}
return 0;
}