#include <bits/stdc++.h>
using namespace std;
int n;
vector<long long> S;
vector<int> N, L, R;
vector<bool> E;
pair<long long, pair<int, int>> merge(int l, int r, int mid,
                                      pair<long long, pair<int, int>> L,
                                      pair<long long, pair<int, int>> R) {
  int ll = L.second.first, lr = L.second.second;
  int rl = R.second.first, rr = R.second.second;
  long long ls = L.first, rs = R.first;
  long long sum = ls + rs;
  int lw = ll, rw = rr;
  int lLength = mid - l + 1, rLength = r - (mid + 1) + 1;
  if (lr && rl && N[mid + 1] >= N[mid]) {
    if (ll == lLength) lw += rl;
    if (rr == rLength) rw += lr;
    if (ll != lLength && rl != rLength)
      sum += (long long)(lr + rl) * (lr + rl - 1) / 2;
  } else {
    if (ll != lLength) sum += (long long)(lr) * (lr - 1) / 2;
    if (rr != rLength) sum += (long long)(rl) * (rl - 1) / 2;
  }
  return {sum, {lw, rw}};
}
pair<long long, pair<int, int>> getVal(int lq, int rq, int l = 0, int r = n - 1,
                                       int index = 0) {
  if (l == r) return {0, {1, 1}};
  if (lq == l && rq == r && E[index]) return {S[index], {L[index], R[index]}};
  int mid = (l + r) >> 1;
  if (rq <= mid) {
    return getVal(lq, rq, l, mid, 2 * index + 1);
  } else if (lq > mid) {
    return getVal(lq, rq, mid + 1, r, 2 * index + 2);
  }
  auto lv = getVal(lq, mid, l, mid, 2 * index + 1);
  auto rv = getVal(mid + 1, rq, mid + 1, r, 2 * index + 2);
  auto ret = merge(lq, rq, mid, lv, rv);
  if (l == lq && r == rq) {
    E[index] = true;
    S[index] = ret.first, L[index] = ret.second.first,
    R[index] = ret.second.second;
  }
  return ret;
}
void update(int lq, int rq, int l = 0, int r = n - 1, int index = 0) {
  if (l == r) return;
  E[index] = false;
  int mid = (l + r) >> 1;
  if (rq <= mid) {
    return update(lq, rq, l, mid, 2 * index + 1);
  } else if (lq > mid) {
    return update(lq, rq, mid + 1, r, 2 * index + 2);
  }
  update(lq, mid, l, mid, 2 * index + 1);
  update(mid + 1, rq, mid + 1, r, 2 * index + 2);
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> n >> q;
  N = vector<int>(n);
  S = vector<long long>(4 * n + 1);
  L = R = vector<int>(4 * n + 1);
  E = vector<bool>(4 * n + 1, false);
  for (auto &it : N) cin >> it;
  int cmd, x, y;
  for (int qq = 0; qq < q; qq++) {
    cin >> cmd >> x >> y;
    if (cmd == 1) {
      N[x - 1] = y;
      update(x - 1, x - 1);
    } else {
      x--, y--;
      auto res = getVal(x, y);
      auto sum = res.first;
      int l = res.second.first, r = res.second.second;
      if (l == (y - x + 1))
        sum += (long long)(l) * (l - 1) / 2;
      else
        sum += ((long long)(l) * (l - 1) + (long long)(r) * (r - 1)) / 2;
      sum += (y - x + 1);
      cout << sum << '\n';
    }
  }
  return 0;
}
