#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int N = 2e5 + 10;
struct Node {
  int l, r;
  long long sum;
  int lv, rv;
  int llen, rlen;
} tr[N * 4];
int a[N];
int n, m;
void pushup(Node& u, Node& l, Node& r) {
  u.sum = l.sum + r.sum;
  u.lv = l.lv, u.rv = r.rv;
  u.llen = l.llen, u.rlen = r.rlen;
  if (l.rv <= r.lv) {
    u.sum += (long long)l.rlen * r.llen;
    if (l.llen == l.r - l.l + 1) u.llen += r.llen;
    if (r.rlen == r.r - r.l + 1) u.rlen += l.rlen;
  }
}
void pushup(int u) { pushup(tr[u], tr[u << 1], tr[u << 1 | 1]); }
void build(int u, int l, int r) {
  tr[u] = {l, r};
  if (l == r) {
    tr[u].sum = 1ll;
    tr[u].lv = tr[u].rv = a[l];
    tr[u].llen = tr[u].rlen = 1;
    return;
  }
  int mid = l + r >> 1;
  build(u << 1, l, mid);
  build(u << 1 | 1, mid + 1, r);
  pushup(u);
}
void modify(int u, int pos, int val) {
  if (tr[u].l == tr[u].r) {
    tr[u].sum = 1;
    tr[u].lv = tr[u].rv = val;
    tr[u].llen = tr[u].rlen = 1;
    return;
  }
  int mid = tr[u].l + tr[u].r >> 1;
  if (pos <= mid)
    modify(u << 1, pos, val);
  else
    modify(u << 1 | 1, pos, val);
  pushup(u);
}
Node query(int u, int l, int r) {
  if (tr[u].l >= l && tr[u].r <= r) return tr[u];
  int mid = tr[u].l + tr[u].r >> 1;
  if (r <= mid)
    return query(u << 1, l, r);
  else if (l > mid)
    return query(u << 1 | 1, l, r);
  Node ans = {0}, L = {0}, R = {0};
  L = query(u << 1, l, r);
  R = query(u << 1 | 1, l, r);
  pushup(ans, L, R);
  return ans;
}
signed main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  build(1, 1, n);
  while (m--) {
    int op, a, b;
    scanf("%d%d%d", &op, &a, &b);
    if (op == 1)
      modify(1, a, b);
    else {
      printf("%lld\n", query(1, a, b).sum);
    }
  }
  return 0;
}
