#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n, q, a[MAXN];
struct SegmentTree {
  int pref[MAXN << 2], suf[MAXN << 2];
  long long cnt[MAXN << 2];
  void build(int o, int l, int r) {
    if (r == l) {
      pref[o] = suf[o] = l;
      cnt[o] = 1;
      return;
    }
    int mid = (l + r) / 2;
    build(o * 2, l, mid);
    build(o * 2 + 1, mid + 1, r);
    pref[o] = pref[o * 2];
    suf[o] = suf[o * 2 + 1];
    cnt[o] = cnt[o * 2] + cnt[o * 2 + 1];
    if (a[mid + 1] >= a[mid]) {
      if (pref[o * 2] == mid) pref[o] = pref[o * 2 + 1];
      if (suf[o * 2 + 1] == mid + 1) suf[o] = suf[o * 2];
      cnt[o] += 1ll * (mid - suf[o * 2] + 1) * (pref[o * 2 + 1] - mid);
    }
  }
  void modify(int o, int l, int r, int p, int v) {
    if (r == l) {
      a[l] = v;
      return;
    }
    int mid = (l + r) / 2;
    if (p <= mid) modify(o * 2, l, mid, p, v);
    if (p > mid) modify(o * 2 + 1, mid + 1, r, p, v);
    pref[o] = pref[o * 2];
    suf[o] = suf[o * 2 + 1];
    cnt[o] = cnt[o * 2] + cnt[o * 2 + 1];
    if (a[mid + 1] >= a[mid]) {
      if (pref[o * 2] == mid) pref[o] = pref[o * 2 + 1];
      if (suf[o * 2 + 1] == mid + 1) suf[o] = suf[o * 2];
      cnt[o] += 1ll * (mid - suf[o * 2] + 1) * (pref[o * 2 + 1] - mid);
    }
  }
  long long query(int o, int l, int r, int ql, int qr, long long &strk) {
    if (l >= ql && r <= qr) {
      long long res = cnt[o];
      if (strk && a[l - 1] <= a[l]) res += strk * (pref[o] - l + 1);
      if (a[l - 1] <= a[l] && pref[o] == r) {
        strk += r - l + 1;
      } else {
        strk = r - suf[o] + 1;
      }
      return res;
    }
    int mid = (l + r) / 2;
    long long ret = 0;
    if (ql <= mid) ret += query(o * 2, l, mid, ql, qr, strk);
    if (qr > mid) ret += query(o * 2 + 1, mid + 1, r, ql, qr, strk);
    return ret;
  }
} tree;
void solve() {
  cin >> n >> q;
  for (int i = (1); i <= (n); ++i) cin >> a[i];
  tree.build(1, 1, n);
  while (q--) {
    int t, x, y;
    cin >> t >> x >> y;
    if (t == 1) {
      tree.modify(1, 1, n, x, y);
    } else {
      long long strk = 0;
      cout << tree.query(1, 1, n, x, y, strk) << '\n';
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int _;
  _ = 1;
  while (_--) {
    solve();
  }
  return 0;
}
