#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr ll INF = 2e18;
constexpr ld EPS = 1e-9;
constexpr ll MOD = 1e9 + 7;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
template <typename T1, typename T2>
using safe_map = unordered_map<T1, T2, custom_hash>;
template <typename T1, typename T2>
istream &operator>>(istream &istream, pair<T1, T2> &p) {
  return (istream >> p.first >> p.second);
}
template <typename T>
istream &operator>>(istream &istream, vector<T> &v) {
  for (auto &it : v) cin >> it;
  return istream;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &ostream, const pair<T1, T2> &p) {
  return (ostream << p.first << " " << p.second);
}
template <typename T>
ostream &operator<<(ostream &ostream, const vector<T> &c) {
  for (auto &it : c) cout << it << " ";
  return ostream;
}
template <typename T>
void print(T &&t) {
  cout << t << "\n";
}
template <typename T, typename... Args>
void print(T &&t, Args &&...args) {
  cout << t << " ";
  print(forward<Args>(args)...);
}
template <typename T>
int32_t size_i(T &container) {
  return static_cast<int32_t>(container.size());
}
long long GCD(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long GCD_extended(long long a, long long b, long long &x, long long &y) {
  x = 1, y = 0;
  long long x1 = 0, y1 = 1, a1 = a, b1 = b;
  while (b1) {
    long long q = a1 / b1;
    tie(x, x1) = make_tuple(x1, x - q * x1);
    tie(y, y1) = make_tuple(y1, y - q * y1);
    tie(a1, b1) = make_tuple(b1, a1 - q * b1);
  }
  return a1;
}
long long LCM(long long a, long long b) { return (a * b) / GCD(a, b); }
long long modpow(ll x, long long n, long long m = MOD) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = (res * x) % m;
    x = (x * x) % m;
    n >>= 1;
  }
  return res;
}
long long modinv(long long x, long long m = MOD) { return modpow(x, m - 2, m); }
mt19937 rng;
long long getRandomNumber(long long l, long long r) {
  uniform_int_distribution<long long> dist(l, r);
  return dist(rng);
}
void preSolve() {
  rng = mt19937(chrono::steady_clock::now().time_since_epoch().count());
}
template <typename Data, typename Node>
class SegTree {
  long long n;
  vector<Node> st;
  function<Node(Node, Node)> mergeFn;

 public:
  SegTree() = default;
  SegTree(const vector<Data> &data, const function<Node(Node, Node)> &fn) {
    n = data.size();
    st = vector<Node>(4 * n);
    mergeFn = fn;
    build(data, 1, 0, n - 1);
  }
  Node query(long long l, long long r) { return queryImpl(l, r, 1, 0, n - 1); };
  void pointUpdate(long long pos, const Data &val) {
    return pointUpdateImpl(pos, val, 1, 0, n - 1);
  }

 private:
  void build(const vector<Data> &data, long long v, long long l, long long r) {
    if (l == r)
      st[v] = data[l];
    else {
      long long mid = (l + r) / 2;
      build(data, 2 * v, l, mid);
      build(data, 2 * v + 1, mid + 1, r);
      st[v] = mergeFn(st[v * 2], st[v * 2 + 1]);
    }
  }
  Node queryImpl(long long l, long long r, long long v, long long nL,
                 long long nR) {
    if (l > r) return Node{};
    if (nL == l && nR == r) return st[v];
    long long mid = (nL + nR) / 2;
    return mergeFn(queryImpl(l, min(r, mid), 2 * v, nL, mid),
                   queryImpl(max(l, mid + 1), r, 2 * v + 1, mid + 1, nR));
  }
  void pointUpdateImpl(long long pos, const Data &val, long long v,
                       long long nL, long long nR) {
    if (nL == nR) {
      st[v] = val;
      return;
    }
    long long mid = (nL + nR) / 2;
    if (pos <= mid)
      pointUpdateImpl(pos, val, 2 * v, nL, mid);
    else
      pointUpdateImpl(pos, val, 2 * v + 1, mid + 1, nR);
    st[v] = mergeFn(st[2 * v], st[2 * v + 1]);
  }
};
struct Node {
  long long first, last, pref, suf, len, ans;
  Node() : first(0), last(0), pref(0), suf(0), len(0), ans(0) {}
  Node(long long x) : first(x), last(x), pref(1), suf(1), len(1), ans(1) {}
};
Node merge(Node l, Node r) {
  Node ans;
  ans.first = l.first;
  ans.last = r.last;
  ans.len = l.len + r.len;
  ans.ans = l.ans + r.ans;
  ans.pref = l.pref;
  ans.suf = r.suf;
  if (l.last <= r.first) {
    if (l.len == l.pref) ans.pref = l.len + r.pref;
    if (r.len == r.pref) ans.suf = r.len + l.suf;
    ans.ans += l.suf * r.pref;
  }
  return ans;
}
void solve(long long tc) {
  long long n, q;
  cin >> n >> q;
  vector<long long> a(n);
  cin >> a;
  SegTree<long long, Node> st(a, [](Node l, Node r) {
    Node ans;
    ans.first = l.first;
    ans.last = r.last;
    ans.len = l.len + r.len;
    ans.ans = l.ans + r.ans;
    ans.pref = l.pref;
    ans.suf = r.suf;
    if (l.last <= r.first) {
      if (l.len == l.pref) ans.pref = l.len + r.pref;
      if (r.len == r.pref) ans.suf = r.len + l.suf;
      ans.ans += l.suf * r.pref;
    }
    return ans;
  });
  while (q--) {
    long long t, x, y;
    cin >> t >> x >> y;
    if (t == 1) {
      x--;
      st.pointUpdate(x, y);
    } else {
      x--;
      y--;
      print(st.query(x, y).ans);
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(12) << fixed;
  preSolve();
  long long tests = 1;
  for (long long tt = 1; tt <= tests; tt++) solve(tt);
  return 0;
}
