#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2")
using namespace std;
template <class T1, class T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
template <class T1, class T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& p) {
  out << p.first << ' ' << p.second << '\n';
  return out;
}
template <class T>
istream& operator>>(istream& in, vector<T>& arr) {
  for (T& i : arr) in >> i;
  return in;
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& arr) {
  for (const T& i : arr) out << i << ' ';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<vector<T>>& arr) {
  for (const vector<T>& i : arr) out << i << '\n';
  return out;
}
template <class T>
ostream& operator<<(ostream& out, set<T>& s) {
  for (const T& i : s) {
    out << i << ' ';
  }
  return out;
}
template <class T>
void uniq(vector<T>& a) {
  sort(a.begin(), a.end());
  a.resize(unique(a.begin(), a.end()) - a.begin());
}
struct Node {
  long long val;
  int first, last;
  long long pref, suff;
  int len;
  Node() {
    val = 0;
    first = -2e9;
    last = -2e9;
    pref = 0;
    suff = 0;
    len = 0;
  }
  Node(int a) {
    val = 1;
    first = a;
    last = a;
    pref = 1;
    suff = 1;
    len = 1;
  }
};
Node unite(const Node& a, const Node& b) {
  if (a.last == -2e9) {
    return b;
  }
  if (b.first == -2e9) {
    return a;
  }
  Node res;
  res.val = a.val + b.val;
  res.len = a.len + b.len;
  if (b.first >= a.last) {
    res.val += a.suff * b.pref;
  }
  if (a.pref == a.len && a.last <= b.first) {
    res.pref = a.len + b.pref;
  } else {
    res.pref = a.pref;
  }
  if (b.suff == b.len && a.last <= b.first) {
    res.suff = a.suff + b.len;
  } else {
    res.suff = b.suff;
  }
  res.first = a.first;
  res.last = b.last;
  return res;
}
vector<Node> t;
vector<int> a;
void build(int v, int l, int r) {
  if (r - l == 1) {
    t[v] = Node(a[l]);
    return;
  }
  int m = (l + r) / 2;
  build(v * 2 + 1, l, m);
  build(v * 2 + 2, m, r);
  t[v] = unite(t[v * 2 + 1], t[v * 2 + 2]);
}
Node ask(int v, int l, int r, int askl, int askr) {
  if (l >= askr || r <= askl) {
    return Node();
  }
  if (l >= askl && r <= askr) {
    return t[v];
  }
  int m = (l + r) / 2;
  return unite(ask(v * 2 + 1, l, m, askl, askr),
               ask(v * 2 + 2, m, r, askl, askr));
}
void change(int v, int l, int r, int pos, int val) {
  if (r - l == 1) {
    t[v] = Node(val);
    return;
  }
  int m = (l + r) / 2;
  if (pos < m) {
    change(v * 2 + 1, l, m, pos, val);
  } else {
    change(v * 2 + 2, m, r, pos, val);
  }
  t[v] = unite(t[v * 2 + 1], t[v * 2 + 2]);
}
void solve() {
  int n, q;
  cin >> n >> q;
  t.resize(4 * n);
  a.resize(n);
  cin >> a;
  build(0, 0, n);
  while (q--) {
    int mode, l, r;
    cin >> mode >> l >> r;
    l--;
    if (mode == 1) {
      change(0, 0, n, l, r);
    } else {
      cout << ask(0, 0, n, l, r).val << '\n';
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T;
  T = 1;
  for (int TrT = 0; TrT < (T); TrT++) {
    solve();
  }
  return 0;
}
