#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 2147483647;
int a[maxn];
struct Node {
  int vl, vr, lenl, lenr, len;
  long long ans;
} t[maxn << 2];
Node merge(Node tl, Node tr) {
  Node ans;
  ans.ans = tl.ans + tr.ans;
  ans.len = tl.len + tr.len;
  if (tl.vr <= tr.vl) {
    ans.ans += 1ll * tl.lenr * tr.lenl;
    if (tl.lenr == tl.len)
      ans.lenl = tl.len + tr.lenl;
    else
      ans.lenl = tl.lenl;
    if (tr.lenl == tr.len)
      ans.lenr = tr.len + tl.lenr;
    else
      ans.lenr = tr.lenr;
  } else
    ans.lenl = tl.lenl, ans.lenr = tr.lenr;
  ans.vl = tl.vl, ans.vr = tr.vr;
  return ans;
}
void pushup(int rt) { t[rt] = merge(t[rt << 1], t[rt << 1 | 1]); }
void build(int rt, int l, int r) {
  if (l == r) {
    t[rt] = Node{a[l], a[l], 1, 1, 1, 1};
    return;
  }
  int mid = l + r >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  pushup(rt);
}
void cg(int rt, int l, int r, int x, int v) {
  if (l == r) {
    t[rt] = Node{v, v, 1, 1, 1, 1};
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid) cg(rt << 1, l, mid, x, v);
  if (x >= mid + 1) cg(rt << 1 | 1, mid + 1, r, x, v);
  pushup(rt);
}
Node qry(int rt, int l, int r, int ql, int qr) {
  if (l >= ql && r <= qr) {
    return t[rt];
  }
  int mid = l + r >> 1;
  Node ans;
  if (qr <= mid)
    ans = qry(rt << 1, l, mid, ql, qr);
  else if (ql >= mid + 1)
    ans = qry(rt << 1 | 1, mid + 1, r, ql, qr);
  else
    ans = merge(qry(rt << 1, l, mid, ql, qr),
                qry(rt << 1 | 1, mid + 1, r, ql, qr));
  return ans;
}
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  build(1, 1, n);
  while (q--) {
    int op, x, y;
    scanf("%d%d%d", &op, &x, &y);
    if (op == 1) {
      cg(1, 1, n, x, y);
    } else {
      Node ans = qry(1, 1, n, x, y);
      printf("%lld\n", ans.ans);
    }
  }
}
