#include <cstdio>
#include <iostream>
#include <algorithm>
#define maxn 100000
#define inf -1000000
using namespace std;
int maxv[4 * maxn], a[maxn], sum[4 * maxn];
//建树
void build(int id, int l, int r){
if(l == r){
maxv[id] = a[l];
sum[id] = a[l];
return;
}
int mid = (l + r) >> 1;
build(id << 1, l, mid);
build(id << 1 | 1, mid + 1, r);
maxv[id] = max(maxv[id << 1], maxv[id << 1| 1]);
sum[id] = sum[id << 1] + sum[id << 1| 1];
}
//把x变成v
void update(int id, int l, int r, int x, int v){
if(l == r){
maxv[id] = v;
sum[id] = v;
return;
}
int mid = (l + r) >> 1;
if(x <= mid){
update(id << 1, l, mid, x, v);
}
else{
update(id << 1 | 1, mid + 1, r, x, v);
}
maxv[id] = max(maxv[id << 1], maxv[id << 1| 1]);
sum[id] = sum[id << 1] + sum[id << 1| 1];
}
//求x-y上的最大值
int query_max(int id, int l, int r, int x, int y){
if(x <= l && y >= r){
return maxv[id];
}
int mid = (l + r) >> 1;
int ans = inf;
if(x <= mid){
ans = max(ans, query_max(id << 1, l, mid, x, y));
}
if(y > mid){
ans = max(ans, query_max(id << 1 | 1, mid + 1, r, x, y));
}
return ans;
}
//求x-y上的和
int query_sum(int id, int l, int r, int x, int y){
if(x <= l && y >= r){
return sum[id];
}
int mid = (l + r) >> 1;
int ans = 0;
if(x <= mid){
ans += query_sum(id << 1, l, mid, x, y);
}
if(y > mid){
ans += query_sum(id << 1 | 1, mid + 1, r, x, y);
}
return ans;
}
int main(){
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
build(1, 1, n);
for(int i = 0; i < m; i++){
int a, b, c;
cin >> a >> b >> c;
if(a == 1){
update(1, 1, n, b, c);
}
else if(a == 2){
cout<< query_sum(1, 1, n, b, c) << endl;
}
else{
cout<< query_max(1, 1, n, b, c) << endl;
}
}
return 0;
}