#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int N = 2e5 + 5;
long long int n, m, a[N] = {0};
struct Node {
  long long int cnt = 0, lmax = 0, rmax = 0;
};
Node t[4 * N];
void build(long long int pos, long long int l, long long int r) {
  if (l == r) {
    t[pos].cnt = t[pos].lmax = t[pos].rmax = 1;
    return;
  }
  long long int mid = (l + r) / 2;
  build(2 * pos, l, mid);
  build(2 * pos + 1, mid + 1, r);
  if (a[mid] <= a[mid + 1]) {
    t[pos].cnt = t[2 * pos].cnt + t[2 * pos + 1].cnt +
                 (t[2 * pos].rmax * t[2 * pos + 1].lmax);
    t[pos].lmax = t[2 * pos].lmax;
    t[pos].rmax = t[2 * pos + 1].rmax;
    if (t[2 * pos].lmax == (mid - l + 1))
      t[pos].lmax = mid - l + 1 + t[2 * pos + 1].lmax;
    if (t[2 * pos + 1].rmax == (r - mid))
      t[pos].rmax = r - mid + t[2 * pos].rmax;
  } else {
    t[pos].cnt = t[2 * pos].cnt + t[2 * pos + 1].cnt;
    t[pos].lmax = t[2 * pos].lmax;
    t[pos].rmax = t[2 * pos + 1].rmax;
  }
}
Node query(long long int pos, long long int ql, long long int qr,
           long long int l, long long int r) {
  Node ret;
  if (ql > r || l > qr) return ret;
  if (ql <= l && r <= qr) return t[pos];
  long long int mid = (l + r) / 2;
  Node r1 = query(2 * pos, ql, qr, l, mid);
  Node r2 = query(2 * pos + 1, ql, qr, mid + 1, r);
  if (a[mid] <= a[mid + 1]) {
    ret.cnt = r1.cnt + r2.cnt + (r1.rmax * r2.lmax);
    ret.lmax = r1.lmax;
    ret.rmax = r2.rmax;
    if (r1.lmax == (mid - l + 1)) ret.lmax = mid - l + 1 + r2.lmax;
    if (r2.rmax == (r - mid)) ret.rmax = r - mid + r1.rmax;
  } else {
    ret.cnt = r1.cnt + r2.cnt;
    ret.lmax = r1.lmax;
    ret.rmax = r2.rmax;
  }
  return ret;
}
void update(long long int pos, long long int idx, long long int l,
            long long int r, long long int x) {
  if (l == r) {
    a[idx] = x;
    return;
  }
  long long int mid = (l + r) / 2;
  if (idx > mid)
    update(2 * pos + 1, idx, mid + 1, r, x);
  else
    update(2 * pos, idx, l, mid, x);
  if (a[mid] <= a[mid + 1]) {
    t[pos].cnt = t[2 * pos].cnt + t[2 * pos + 1].cnt +
                 (t[2 * pos].rmax * t[2 * pos + 1].lmax);
    t[pos].lmax = t[2 * pos].lmax;
    t[pos].rmax = t[2 * pos + 1].rmax;
    if (t[2 * pos].lmax == (mid - l + 1))
      t[pos].lmax = mid - l + 1 + t[2 * pos + 1].lmax;
    if (t[2 * pos + 1].rmax == (r - mid))
      t[pos].rmax = r - mid + t[2 * pos].rmax;
  } else {
    t[pos].cnt = t[2 * pos].cnt + t[2 * pos + 1].cnt;
    t[pos].lmax = t[2 * pos].lmax;
    t[pos].rmax = t[2 * pos + 1].rmax;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, j, k, x, y;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> a[i];
  build(1, 1, n);
  while (m--) {
    cin >> k >> x >> y;
    if (k == 1)
      update(1, x, 1, n, y);
    else {
      Node res = query(1, x, y, 1, n);
      cout << res.cnt << '\n';
    }
  }
  return 0;
}
