#include <bits/stdc++.h>
using namespace std;
const long long N = 200010;
struct node {
  long long sum, l, r, L, R, s;
} tr[N * 4];
long long n, m, a[N];
void pushup(node &root, node l, node r) {
  root.sum = l.sum + r.sum;
  root.s = l.s + r.s;
  root.l = l.l, root.r = r.r;
  root.L = l.L, root.R = r.R;
  if (l.r <= r.l) {
    root.sum += l.R * r.L;
    if (l.L == l.s) root.L += r.L;
    if (r.R == r.s) root.R += l.R;
  }
}
void build(long long u, long long l, long long r) {
  if (l == r) {
    tr[u] = {1, a[l], a[r], 1, 1, 1};
    return;
  }
  long long mid = l + r >> 1;
  build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
  pushup(tr[u], tr[u << 1], tr[u << 1 | 1]);
}
node query(long long u, long long l, long long r, long long ql, long long qr) {
  if (ql <= l && qr >= r)
    return tr[u];
  else {
    long long mid = l + r >> 1;
    if (qr <= mid)
      return query(u << 1, l, mid, ql, qr);
    else if (ql > mid)
      return query(u << 1 | 1, mid + 1, r, ql, qr);
    else {
      node ansl = query(u << 1, l, mid, ql, qr);
      node ansr = query(u << 1 | 1, mid + 1, r, ql, qr);
      node ans;
      pushup(ans, ansl, ansr);
      return ans;
    }
  }
}
void modify(long long u, long long l, long long r, long long pos, long long v) {
  if (l == r)
    tr[u] = {1, v, v, 1, 1, 1};
  else {
    long long mid = l + r >> 1;
    if (pos <= mid)
      modify(u << 1, l, mid, pos, v);
    else
      modify(u << 1 | 1, mid + 1, r, pos, v);
    pushup(tr[u], tr[u << 1], tr[u << 1 | 1]);
  }
}
signed main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  build(1, 1, n);
  while (m--) {
    long long t, first, second;
    cin >> t >> first >> second;
    if (t == 1)
      modify(1, 1, n, first, second);
    else {
      cout << query(1, 1, n, first, second).sum << endl;
    }
  }
  return 0;
}
