#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
int n, q, a[N];
long long f(long long n) { return n * (n + 1) / 2; }
struct NodeType {
  long long num;
  int len, pref, suff, prefVal, suffVal;
  friend NodeType combine(const NodeType &a, const NodeType &b) {
    NodeType c;
    c.len = a.len + b.len;
    c.prefVal = a.prefVal;
    c.suffVal = b.suffVal;
    c.num = a.num + b.num;
    if (a.suffVal <= b.prefVal) {
      c.num = c.num - f(a.suff) - f(b.pref) + f(a.suff + b.pref);
      if (a.suff == a.len)
        c.pref = a.len + b.pref;
      else
        c.pref = a.pref;
      if (b.pref == b.len)
        c.suff = a.suff + b.len;
      else
        c.suff = b.suff;
    } else {
      c.pref = a.pref;
      c.suff = b.suff;
    }
    return c;
  }
};
struct segtree {
  int size;
  vector<NodeType> node;
  void init(int n) {
    size = 1;
    while (size < n) size <<= 1;
    node.assign(size << 1, NodeType());
  }
  void build(int id, int l, int r) {
    node[id].len = r - l + 1;
    if (l == r) {
      node[id].num = node[id].pref = node[id].suff = 1;
      if (l <= n) {
        node[id].prefVal = node[id].suffVal = a[l];
      }
      return;
    }
    int m = l + r >> 1;
    build(id << 1, l, m);
    build(id << 1 | 1, m + 1, r);
    node[id] = combine(node[id << 1], node[id << 1 | 1]);
  }
  void build() { build(1, 1, size); }
  void update(int id, int l, int r, int i, int k) {
    if (l > i || r < i) return;
    if (l == r) {
      node[id].prefVal = node[id].suffVal = k;
      return;
    }
    int m = l + r >> 1;
    update(id << 1, l, m, i, k);
    update(id << 1 | 1, m + 1, r, i, k);
    node[id] = combine(node[id << 1], node[id << 1 | 1]);
  }
  void update(int i, int k) { update(1, 1, size, i, k); }
  NodeType getNum(int id, int l, int r, int x, int y) {
    if (l >= x && r <= y) return node[id];
    int m = l + r >> 1;
    if (m >= y) return getNum(id << 1, l, m, x, y);
    if (m < x) return getNum(id << 1 | 1, m + 1, r, x, y);
    return combine(getNum(id << 1, l, m, x, y),
                   getNum(id << 1 | 1, m + 1, r, x, y));
  }
  long long getNum(int x, int y) { return getNum(1, 1, size, x, y).num; }
} st;
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  st.init(n);
  st.build();
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int i, k;
      cin >> i >> k;
      st.update(i, k);
    } else {
      int x, y;
      cin >> x >> y;
      cout << st.getNum(x, y) << '\n';
    }
  }
  return 0;
}
