#include <bits/stdc++.h>
using namespace std;
char *p1, *p2, buf[100000];
long long read() {
  long long x = 0, f = 1;
  char ch =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
           ? EOF
           : *p1++);
  while (ch<48 | ch> 57) {
    if (ch == '-') f = -1;
    ch = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
              ? EOF
              : *p1++);
  }
  while (ch >= 48 && ch <= 57)
    x = x * 10 + ch - 48,
    ch = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
              ? EOF
              : *p1++);
  return x * f;
}
const long long maxn = 2e5 + 105;
long long a[maxn], bit[maxn], n, m, op, x, y;
set<long long> s;
void add(long long x, long long y) {
  for (; x < maxn; x += (x & -x)) bit[x] += y;
}
long long sum(long long x) {
  long long ret = 0;
  for (; x; x -= (x & -x)) ret += bit[x];
  return ret;
}
void del(long long x) {
  auto it = s.find(x);
  add(x, -((x - *prev(it)) * (x - *prev(it) + 1) / 2));
  add(*next(it), -((*next(it) - x) * (*next(it) - x + 1) / 2));
  add(*next(it), ((*next(it) - *prev(it)) * (*next(it) - *prev(it) + 1) / 2));
  s.erase(it);
}
void ins(long long x) {
  s.insert(x);
  auto it = s.find(x);
  add(x, ((x - *prev(it)) * (x - *prev(it) + 1) / 2));
  add(*next(it), ((*next(it) - x) * (*next(it) - x + 1) / 2));
  add(*next(it), -((*next(it) - *prev(it)) * (*next(it) - *prev(it) + 1) / 2));
}
signed main() {
  n = read(), m = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  long long last = 0;
  s.insert(0);
  a[n + 2] = -1;
  for (long long i = 1; i <= n + 1; i++) {
    if (a[i] > a[i + 1]) {
      add(i, ((i - last) * (i - last + 1) / 2));
      s.insert(i);
      last = i;
    }
  }
  for (long long i = 1; i <= m; i++) {
    op = read(), x = read(), y = read();
    if (op == 1) {
      if (a[x - 1] > a[x]) del(x - 1);
      if (a[x] > a[x + 1]) del(x);
      a[x] = y;
      if (a[x - 1] > a[x]) ins(x - 1);
      if (a[x] > a[x + 1]) ins(x);
    } else {
      auto it = s.lower_bound(x);
      if (*it >= y) {
        cout << ((y - x + 1) * (y - x + 1 + 1) / 2) << "\n";
        continue;
      }
      long long ans = sum(y) - sum(*it);
      auto it2 = s.upper_bound(y);
      ans += ((y - *prev(it2)) * (y - *prev(it2) + 1) / 2);
      ans += ((*it - x + 1) * (*it - x + 1 + 1) / 2);
      cout << ans << "\n";
    }
  }
  return 0;
}
