#include <bits/stdc++.h>
using namespace std;
struct st {
  long long int tot;
  long long int pretot;
  long long int preval;
  long long int sufftot;
  long long int suffval;
  long long int count;
};
st t[800005];
void build(long long int a[], long long int v, long long int tl,
           long long int tr) {
  if (tl == tr) {
    t[v].tot = 2;
    t[v].pretot = 1;
    t[v].preval = a[tl];
    t[v].sufftot = 1;
    t[v].suffval = a[tl];
    t[v].count = 1;
  } else {
    long long int tm = (tl + tr) / 2;
    build(a, 2 * v, tl, tm);
    build(a, 2 * v + 1, tm + 1, tr);
    t[v].count = t[2 * v].count + t[2 * v + 1].count;
    t[v].tot = t[2 * v].tot + t[2 * v + 1].tot;
    t[v].pretot = t[2 * v].pretot;
    t[v].preval = t[2 * v].preval;
    t[v].sufftot = t[2 * v + 1].sufftot;
    t[v].suffval = t[2 * v + 1].suffval;
    if (t[2 * v + 1].preval >= t[2 * v].suffval) {
      t[v].count--;
      t[v].tot += 2 * t[2 * v].sufftot * t[2 * v + 1].pretot;
      if (t[2 * v].count == 1) {
        t[v].pretot += t[2 * v + 1].pretot;
      }
      if (t[2 * v + 1].count == 1) {
        t[v].sufftot += t[2 * v].sufftot;
      }
    }
  }
}
st sum(long long int v, long long int tl, long long int tr, long long int l,
       long long int r) {
  st temp;
  temp.tot = 0;
  temp.count = 0;
  temp.preval = 0;
  temp.pretot = 0;
  ;
  temp.sufftot = 0;
  temp.suffval = 0;
  if (l > r) return temp;
  if (l == tl && r == tr) {
    return t[v];
  }
  long long int tm = (tl + tr) / 2;
  st x = sum(2 * v, tl, tm, l, min(r, tm));
  st y = sum(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
  temp.count = x.count + y.count;
  temp.tot = x.tot + y.tot;
  temp.pretot = x.pretot;
  temp.preval = x.preval;
  temp.sufftot = y.sufftot;
  temp.suffval = y.suffval;
  if (y.preval >= x.suffval) {
    temp.count--;
    temp.tot += 2 * x.sufftot * y.pretot;
    if (x.count == 1) {
      temp.pretot += y.pretot;
    }
    if (y.count == 1) {
      temp.sufftot += x.sufftot;
    }
  }
  return temp;
}
void update(long long int v, long long int tl, long long int tr,
            long long int pos, long long int new_val) {
  if (tl == tr) {
    t[v].tot = 2;
    t[v].pretot = 1;
    t[v].preval = new_val;
    t[v].sufftot = 1;
    t[v].suffval = new_val;
    t[v].count = 1;
  } else {
    long long int tm = (tl + tr) / 2;
    if (pos <= tm)
      update(2 * v, tl, tm, pos, new_val);
    else
      update(2 * v + 1, tm + 1, tr, pos, new_val);
    t[v].count = t[2 * v].count + t[2 * v + 1].count;
    t[v].tot = t[2 * v].tot + t[2 * v + 1].tot;
    t[v].pretot = t[2 * v].pretot;
    t[v].preval = t[2 * v].preval;
    t[v].sufftot = t[2 * v + 1].sufftot;
    t[v].suffval = t[2 * v + 1].suffval;
    if (t[2 * v + 1].preval >= t[2 * v].suffval) {
      t[v].count--;
      t[v].tot += 2 * t[2 * v].sufftot * t[2 * v + 1].pretot;
      if (t[2 * v].count == 1) {
        t[v].pretot += t[2 * v + 1].pretot;
      }
      if (t[2 * v + 1].count == 1) {
        t[v].sufftot += t[2 * v].sufftot;
      }
    }
  }
}
void solve() {
  long long int n, q;
  cin >> n >> q;
  long long int arr[n];
  for (long long int i = 0; i < n; i++) cin >> arr[i];
  build(arr, 1, 0, n - 1);
  while (q--) {
    long long int type;
    cin >> type;
    if (type == 1) {
      long long int ind, val;
      cin >> ind >> val;
      ind -= 1;
      update(1, 0, n - 1, ind, val);
    } else {
      long long int l, r;
      cin >> l >> r;
      l -= 1;
      r -= 1;
      cout << sum(1, 0, n - 1, l, r).tot / 2 << endl;
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  long long int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
