#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct SegTree {
  struct Data {
    ll n_inc, l_inc_len, r_inc_len;
  } tree[200001 << 2];
  int origin[200001];
  Data combine(Data a, Data b, int L, int R, int mid) {
    Data result;
    if (origin[mid] <= origin[mid + 1]) {
      result.n_inc = a.n_inc + b.n_inc + a.r_inc_len * b.l_inc_len;
      result.l_inc_len =
          a.l_inc_len == mid - L + 1 ? mid - L + 1 + b.l_inc_len : a.l_inc_len;
      result.r_inc_len =
          b.r_inc_len == R - mid ? R - mid + a.r_inc_len : b.r_inc_len;
    } else {
      result.n_inc = a.n_inc + b.n_inc;
      result.l_inc_len = a.l_inc_len;
      result.r_inc_len = b.r_inc_len;
    }
    return result;
  }
  void build(int node, int L, int R) {
    if (L == R) {
      tree[node] = {1, 1, 1};
      return;
    }
    int mid = L + R >> 1;
    build(node * 2 + 1, L, mid);
    build(node * 2 + 2, mid + 1, R);
    tree[node] = combine(tree[node * 2 + 1], tree[node * 2 + 2], L, R, mid);
  }
  void update(int node, int L, int R, int index, int value) {
    if (L == R) {
      origin[L] = value;
      return;
    }
    int mid = L + R >> 1;
    if (index <= mid) {
      update(node * 2 + 1, L, mid, index, value);
    } else {
      update(node * 2 + 2, mid + 1, R, index, value);
    }
    tree[node] = combine(tree[node * 2 + 1], tree[node * 2 + 2], L, R, mid);
  }
  Data query(int node, int L, int R, int l, int r) {
    if (l <= L && R <= r) {
      return tree[node];
    }
    if (L > r || R < l) {
      return {0, 0, 0};
    }
    int mid = L + R >> 1;
    return combine(query(node * 2 + 1, L, mid, l, r),
                   query(node * 2 + 2, mid + 1, R, l, r), L, R, mid);
  }
} segtree;
void solve() {
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> segtree.origin[i];
  }
  segtree.build(0, 1, n);
  for (int i = 1, type, l, r; i <= q; i++) {
    cin >> type >> l >> r;
    if (type == 1) {
      segtree.update(0, 1, n, l, r);
    } else {
      cout << segtree.query(0, 1, n, l, r).n_inc << '\n';
    }
  }
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
