#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
struct info {
  ll ls, rs, sum, len;
  ll sl, sr;
  info operator+(const info &t) {
    ll nls = (ls == len && sr <= t.sl) ? (ls + t.ls) : ls;
    ll nrs = (t.rs == t.len && sr <= t.sl) ? (t.rs + rs) : t.rs;
    ll nlen = len + t.len;
    ll nsum = sum + t.sum;
    if (sr <= t.sl) nsum += rs * t.ls;
    return info{nls, nrs, nsum, nlen, sl, t.sr};
  }
};
struct Segment {
  vector<info> sum;
  Segment(int n) : sum(n << 2) {}
  void pushup(int pos) { sum[pos] = sum[pos << 1] + sum[pos << 1 | 1]; }
  info query(int ql, int qr, int pos, int l, int r) {
    if (ql <= l && r <= qr) {
      return sum[pos];
    }
    int mid = (l + r) >> 1;
    if (qr <= mid) {
      return query(ql, qr, pos << 1, l, mid);
    } else if (ql > mid) {
      return query(ql, qr, pos << 1 | 1, mid + 1, r);
    } else {
      return query(ql, qr, pos << 1, l, mid) +
             query(ql, qr, pos << 1 | 1, mid + 1, r);
    }
  }
  void update(int v, int w, int pos, int l, int r) {
    if (l == r) {
      sum[pos].sl = sum[pos].sr = w;
      return;
    }
    int mid = (l + r) >> 1;
    if (v <= mid)
      update(v, w, pos << 1, l, mid);
    else
      update(v, w, pos << 1 | 1, mid + 1, r);
    pushup(pos);
  }
  void build(int pos, int l, int r, vector<int> &a) {
    if (l == r) {
      sum[pos] = info{1, 1, 1, 1, a[l], a[l]};
      return;
    }
    int mid = (l + r) >> 1;
    build(pos << 1, l, mid, a);
    build(pos << 1 | 1, mid + 1, r, a);
    pushup(pos);
  }
};
void solve() {
  int n, q;
  cin >> n >> q;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];
  Segment t(n);
  t.build(1, 1, n, a);
  while (q--) {
    int op, x, y;
    cin >> op >> x >> y;
    if (op == 1) {
      t.update(x, y, 1, 1, n);
    } else {
      cout << t.query(x, y, 1, 1, n).sum << endl;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  while (T--) {
    solve();
  }
}
