#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long read() {
  long long s = 0;
  char c = getchar(), lc = '+';
  while (c < '0' || '9' < c) lc = c, c = getchar();
  while ('0' <= c && c <= '9') s = s * 10 + c - '0', c = getchar();
  return lc == '-' ? -s : s;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x < 10)
    putchar(x + '0');
  else
    write(x / 10), putchar(x % 10 + '0');
}
void print(long long x, char c = '\n') {
  write(x);
  putchar(c);
}
long long a[N], n, q;
struct node {
  long long sum, len, tag;
  node() { tag = -1; }
  void update(long long x) {
    tag = x;
    sum = len * x;
  }
} t[N * 4];
node operator+(const node &a, const node &b) {
  node ret;
  ret.sum = a.sum + b.sum;
  ret.len = a.len + b.len;
  return ret;
}
void push_down(long long w) {
  if (!~t[w].tag) return;
  t[(w * 2)].update(t[w].tag);
  t[(w * 2 + 1)].update(t[w].tag);
  t[w].tag = -1;
}
void cover(long long w, long long l, long long r, long long ql, long long qr,
           long long x) {
  if (r < ql || qr < l) return;
  if (ql <= l && r <= qr) return t[w].update(x);
  if (l < r) push_down(w);
  cover((w * 2), l, ((l + r) / 2), ql, qr, x);
  cover((w * 2 + 1), ((l + r) / 2) + 1, r, ql, qr, x);
  t[w] = t[(w * 2)] + t[(w * 2 + 1)];
}
long long query(long long w, long long l, long long r, long long ql,
                long long qr) {
  if (r < ql || qr < l) return 0;
  if (ql <= l && r <= qr) return t[w].sum;
  if (l < r) push_down(w);
  return query((w * 2), l, ((l + r) / 2), ql, qr) +
         query((w * 2 + 1), ((l + r) / 2) + 1, r, ql, qr);
}
void build(long long w, long long l, long long r) {
  if (l == r) {
    t[w].len = 1;
    t[w].sum = 0;
    return;
  }
  build((w * 2), l, ((l + r) / 2));
  build((w * 2 + 1), ((l + r) / 2) + 1, r);
  t[w] = t[(w * 2)] + t[(w * 2 + 1)];
}
set<long long> d;
void insert(long long x) {
  if (d.find(x) != d.end()) return;
  auto r = d.lower_bound(x);
  cover(1, 1, n, (*--r) + 1, x, n - x);
  d.insert(x);
}
void erase(long long x) {
  if (d.find(x) == d.end()) return;
  auto p = d.find(x), l = p, r = p;
  l--, r++;
  cover(1, 1, n, (*l) + 1, x, n - (*r));
  d.erase(p);
}
inline long long calc(long long l, long long r) {
  return (l + r) * (r - l + 1) / 2;
}
signed main(signed bangumi, char *ss969[]) {
  (void)bangumi, (void)ss969;
  n = read(), q = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  build(1, 1, n);
  d.insert(0), d.insert(n);
  for (long long i = 1; i < n; i++)
    if (a[i] > a[i + 1]) insert(i);
  while (q--) {
    long long opt = read(), x = read(), y = read();
    if (opt == 1) {
      a[x] = y;
      if (x > 1) {
        if (a[x - 1] <= a[x])
          erase(x - 1);
        else
          insert(x - 1);
      }
      if (x < n) {
        if (a[x] <= a[x + 1])
          erase(x);
        else
          insert(x);
      }
    } else {
      if (y == n) {
        print(calc(n - y + 1, n - x + 1) - query(1, 1, n, x, y));
        continue;
      }
      auto p = d.upper_bound(y);
      long long tmp = max(*--p, x - 1);
      print(calc(n - y + 1, n - x + 1) - query(1, 1, n, x, tmp) -
            (y - tmp) * (n - y));
    }
  }
  return 0;
}
