#include <bits/stdc++.h>
using namespace std;
void setIO(string name) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  freopen((name + ".in").c_str(), "r", stdin);
  freopen((name + ".out").c_str(), "w", stdout);
}
template <typename T>
void PVecPrint(vector<T>& v) {
  for (int i = 0; i < (int)v.size(); i++)
    cout << v[i].first << "," << v[i].second << ' ';
  cout << '\n';
}
template <class T>
void VecPrint(vector<T>& v) {
  for (int i = 0; i < v.size(); i++) cout << v[i] << ' ';
  cout << '\n';
}
vector<long long int> t(800010, 0), lazy(800010, 0);
void push(int v) {
  t[v * 2] += lazy[v];
  lazy[v * 2] += lazy[v];
  t[v * 2 + 1] += lazy[v];
  lazy[v * 2 + 1] += lazy[v];
  lazy[v] = 0;
}
void push(int id, int val, int l, int r) {
  t[id] += val * 1LL * (r - l + 1);
  lazy[id] += val;
}
void update(int v, int tl, int tr, int l, int r, int addend) {
  if (l > r) return;
  if (l == tl && tr == r) {
    push(v, addend, l, r);
  } else {
    int tm = (tl + tr) / 2;
    push(v * 2, lazy[v], tl, tm);
    push(v * 2 + 1, lazy[v], tm + 1, tr);
    lazy[v] = 0;
    update(v * 2, tl, tm, l, min(r, tm), addend);
    update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, addend);
    t[v] = t[v * 2] + t[v * 2 + 1];
  }
}
long long int query(int v, int tl, int tr, int l, int r) {
  if (l > r) return 0;
  if (l <= tl && tr <= r) return t[v];
  int tm = (tl + tr) / 2;
  return query(v * 2, tl, tm, l, min(r, tm)) +
         query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r) +
         lazy[v] * 1LL * (r - l + 1);
}
set<int> oneIds;
vector<int> v(200010), lis(200010, 0);
int n, q;
void calcLis() {
  lis[n - 1] = 1;
  oneIds.insert(n - 1);
  for (int i = n - 2; i > -1; i--) {
    if (v[i] <= v[i + 1])
      lis[i] = lis[i + 1] + 1;
    else {
      lis[i] = 1;
      oneIds.insert(i);
    }
  }
  for (int i = 0; i < n; i++) update(1, 0, n - 1, i, i, lis[i]);
}
int getPrevOne(int index) {
  auto it = oneIds.lower_bound(index + 1);
  if (it == oneIds.begin()) return -1;
  --it;
  return *it;
}
void handleChange(int index, int val) {
  int newLis = query(1, 0, n - 1, index, index), oldLis = newLis;
  if (index != n - 1) {
    if (val > v[index + 1]) {
      newLis = 1;
      oneIds.insert(index);
    } else {
      if (newLis == 1) oneIds.erase(oneIds.find(index));
      newLis = 1 + query(1, 0, n - 1, index + 1, index + 1);
    }
  }
  if (index != 0) {
    if (v[index - 1] > val) {
      if (oneIds.find(index - 1) == oneIds.end()) {
        int pid = getPrevOne(index - 1);
        update(1, 0, n - 1, pid + 1, index - 1, -oldLis);
        oneIds.insert(index - 1);
      }
    } else {
      int diff, pid;
      if (oneIds.find(index - 1) != oneIds.end()) {
        oneIds.erase(oneIds.find(index - 1));
        pid = getPrevOne(index - 1);
        diff = newLis;
      } else {
        diff = newLis - oldLis;
        pid = getPrevOne(index - 1);
      }
      update(1, 0, n - 1, pid + 1, index - 1, diff);
    }
  }
  update(1, 0, n - 1, index, index, newLis - oldLis);
  v[index] = val;
}
void printSum(int l, int r) {
  long long int ans = query(1, 0, n - 1, l, r);
  int pid = getPrevOne(r);
  if (pid != r) {
    int lis = query(1, 0, n - 1, r, r);
    int t = min(r - pid, r - l + 1);
    ans -= t * 1LL * (lis - 1);
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> q;
  for (int i = 0; i < n; i++) cin >> v[i];
  calcLis();
  int type, l, r;
  while (q--) {
    cin >> type >> l >> r;
    if (type == 1) {
      --l;
      handleChange(l, r);
    } else {
      --l;
      --r;
      printSum(l, r);
    }
  }
}
