#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
struct node {
  int l, r;
  int umax, lmax, rmax;
  int ll, rr;
  long long res;
} tr[N << 2];
int a[N];
long long cal(long long t) { return t * (t + 1) / 2; }
inline void push_up(node &now, node &ls, node &rs) {
  now.ll = ls.ll;
  now.rr = rs.rr;
  now.res = ls.res + rs.res;
  now.lmax = ls.lmax;
  now.rmax = rs.rmax;
  if (ls.rr <= rs.ll) {
    now.res -= cal(ls.rmax);
    now.res -= cal(rs.lmax);
    now.res += cal(ls.rmax + rs.lmax);
    if (ls.lmax == ls.r - ls.l + 1) now.lmax = ls.r - ls.l + 1 + rs.lmax;
    if (rs.rmax == rs.r - rs.l + 1) now.rmax = rs.r - rs.l + 1 + ls.rmax;
  }
  now.umax = max(ls.rmax + rs.lmax, max(ls.umax, rs.umax));
}
inline void push_up(int now) {
  push_up(tr[now], tr[now << 1], tr[now << 1 | 1]);
}
void build(int now, int l, int r) {
  tr[now].l = l;
  tr[now].r = r;
  if (l == r) {
    tr[now].res = tr[now].umax = tr[now].lmax = tr[now].rmax = 1;
    tr[now].ll = tr[now].rr = a[l];
    return;
  }
  int mid = l + r >> 1;
  build(now << 1, l, mid);
  build(now << 1 | 1, mid + 1, r);
  push_up(now);
}
void modify(int now, int o, int v) {
  if (tr[now].l == tr[now].r)
    tr[now].res = 1, tr[now].rmax = 1, tr[now].lmax = 1, tr[now].umax = 1,
    tr[now].ll = v, tr[now].rr = v;
  else {
    int mid = tr[now].l + tr[now].r >> 1;
    if (mid >= o)
      modify(now << 1, o, v);
    else
      modify(now << 1 | 1, o, v);
    push_up(now);
  }
}
node query(int now, int L, int R) {
  if (L <= tr[now].l && R >= tr[now].r) return tr[now];
  int mid = tr[now].l + tr[now].r >> 1;
  if (R <= mid)
    return query(now << 1, L, R);
  else if (L > mid)
    return query(now << 1 | 1, L, R);
  else {
    node l = query(now << 1, L, R);
    node r = query(now << 1 | 1, L, R);
    node res;
    push_up(res, l, r);
    return res;
  }
}
int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  build(1, 1, n);
  while (q--) {
    int op;
    scanf("%d", &op);
    if (op == 1) {
      int x, y;
      scanf("%d%d", &x, &y);
      modify(1, x, y);
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      printf("%lld\n", query(1, l, r).res);
    }
  }
  return 0;
}
