#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
pair<pair<long long, long long>, pair<long long, long long> > seg[N * 5];
int n, q, a[N];
pair<pair<long long, long long>, pair<long long, long long> > Merge(
    pair<pair<long long, long long>, pair<long long, long long> > A,
    pair<pair<long long, long long>, pair<long long, long long> > B, int last,
    int first) {
  int L1 = A.first.second;
  int L2 = B.first.second;
  int First = a[first];
  int Last = a[last];
  pair<pair<long long, long long>, pair<long long, long long> > C{{0, L1 + L2},
                                                                  {0, 0}};
  C.first.first = A.first.first + B.first.first;
  if (Last <= First) C.first.first += A.second.second * B.second.first;
  C.second.first = A.second.first;
  if (C.second.first == L1 && Last <= First) C.second.first += B.second.first;
  C.second.second = B.second.second;
  if (C.second.second == L2 && Last <= First)
    C.second.second += A.second.second;
  return C;
}
void Upd(int i, int x, int p = 1, int L = 0, int R = n - 1) {
  if (L == R) {
    a[i] = x;
    seg[p] = {{1, 1}, {1, 1}};
    return;
  }
  if (i <= (L + R) / 2)
    Upd(i, x, 2 * p, L, (L + R) / 2);
  else
    Upd(i, x, 2 * p + 1, (L + R) / 2 + 1, R);
  seg[p] = Merge(seg[2 * p], seg[2 * p + 1], (L + R) / 2, (L + R) / 2 + 1);
  return;
}
pair<pair<long long, long long>, pair<long long, long long> > G(int l, int r,
                                                                int p = 1,
                                                                int L = 0,
                                                                int R = n - 1) {
  if (l > R || L > r) return {{0, 0}, {0, 0}};
  if (l <= L && r >= R) return seg[p];
  pair<pair<long long, long long>, pair<long long, long long> > X =
      G(l, r, 2 * p, L, (L + R) / 2);
  pair<pair<long long, long long>, pair<long long, long long> > Y =
      G(l, r, 2 * p + 1, (L + R) / 2 + 1, R);
  return Merge(X, Y, (L + R) / 2, (L + R) / 2 + 1);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> q;
  for (int i = 0, b; i < n; i++) {
    cin >> b;
    Upd(i, b);
  }
  while (q--) {
    int t, x, y;
    cin >> t >> x >> y;
    if (t == 1)
      Upd(x - 1, y);
    else
      cout << G(x - 1, y - 1).first.first << endl;
  }
  return 0;
}
