#include <bits/stdc++.h>
using namespace std;
struct segment_tree {
  int n;
  vector<long long> st1, st2, lazy;
  segment_tree(int n) : n(n), st1(2 * n), st2(2 * n), lazy(2 * n, -1) {}
  inline int id(int b, int e) { return (b + e - 1) | (b != e - 1); }
  void prop(int l, int r) {
    int cur = id(l, r);
    st1[cur] = lazy[cur] * (r - l);
    st2[cur] = lazy[cur];
    if (l + 1 != r) {
      int mid = (l + r + 1) >> 1;
      lazy[id(l, mid)] = lazy[cur];
      lazy[id(mid, r)] = lazy[cur];
    }
    lazy[cur] = -1;
  }
  void upd(int li, int ri, long long v) { upd(0, n, li, ri, v); }
  void upd(int l, int r, int li, int ri, long long v) {
    if (li == ri) return;
    int cur = id(l, r);
    if (lazy[cur] != -1) prop(l, r);
    if (l >= ri || r <= li) return;
    if (li <= l && r <= ri) {
      lazy[cur] = v;
      prop(l, r);
      return;
    }
    int mid = (l + r + 1) >> 1;
    upd(l, mid, li, ri, v);
    upd(mid, r, li, ri, v);
    st1[cur] = st1[id(l, mid)] + st1[id(mid, r)];
    st2[cur] = max(st2[id(l, mid)], st2[id(mid, r)]);
  }
  long long sum(int li, int ri) { return sum(0, n, li, ri); }
  long long sum(int l, int r, int li, int ri) {
    int cur = id(l, r);
    if (lazy[cur] != -1) prop(l, r);
    if (l >= ri || r <= li) return 0;
    if (li <= l && r <= ri) return st1[cur];
    int mid = (l + r + 1) >> 1;
    return sum(l, mid, li, ri) + sum(mid, r, li, ri);
  }
  int first(int p, int v) { return first(0, n, p, v); }
  int first(int l, int r, int p, int v) {
    int cur = id(l, r);
    if (lazy[cur] != -1) prop(l, r);
    if (p >= r) return n;
    if (st2[cur] <= v) return n;
    if (l + 1 == r) return l;
    int mid = (l + r + 1) >> 1;
    int x = first(l, mid, p, v);
    if (x == n) x = first(mid, r, p, v);
    return x;
  }
};
long long sum(long long l, long long r) {
  return r * (r + 1) / 2 - l * (l - 1) / 2;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  segment_tree st(n + 1);
  for (int i = 1, j = 2; i <= n; i = j, ++j) {
    for (; j <= n && a[j] >= a[j - 1]; ++j)
      ;
    st.upd(i, j, i - 1);
  }
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int x, y;
      cin >> x >> y;
      a[x] = y;
      int mn = n + 1;
      if (a[x] >= a[x - 1])
        mn = st.sum(x - 1, x);
      else
        mn = x - 1;
      st.upd(x, x + 1, mn);
      if (x == n || a[x + 1] < a[x]) mn = x;
      if (x < n) {
        int r = st.first(x + 1, x);
        st.upd(x + 1, r, mn);
      }
    } else {
      int l, r;
      cin >> l >> r;
      int x = st.sum(l, l + 1);
      int y = st.first(l, x);
      long long ans =
          sum(l, min(r, y - 1)) - 1LL * (min(r, y - 1) - l + 1) * (l - 1);
      l = y;
      if (l <= r) ans += sum(l, r) - st.sum(l, r + 1);
      cout << ans << '\n';
    }
  }
  return 0;
}
