#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2e5;
long long t[4 * MaxN];
long long getSum(int v, int tl, int tr, int l, int r) {
  if (l > r) return 0;
  if (l == tl && r == tr) {
    return t[v];
  }
  int mid = (tl + tr) / 2;
  return getSum(v * 2, tl, mid, l, min(r, mid)) +
         getSum(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r);
}
void setVal(int v, int tl, int tr, int pos, long long val) {
  if (tl == tr) {
    t[v] = val;
    return;
  }
  int mid = (tl + tr) / 2;
  if (pos <= mid)
    setVal(v * 2, tl, mid, pos, val);
  else
    setVal(v * 2 + 1, mid + 1, tr, pos, val);
  t[v] = t[v * 2] + t[v * 2 + 1];
}
int a[MaxN];
long long f(long long totalLen, long long ignoredLen) {
  return ignoredLen * (ignoredLen + 1) / 2 +
         ignoredLen * (totalLen - ignoredLen);
}
int main(int argc, const char* argv[]) {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) cin >> a[i];
  set<pair<int, int>> segs;
  auto addSeg = [&](int l, int r) {
    segs.insert({l, r});
    int len = r - l + 1;
    setVal(1, 0, n - 1, l, len * 1ll * (len + 1) / 2);
  };
  auto removeSeg = [&](int l, int r) {
    segs.erase({l, r});
    setVal(1, 0, n - 1, l, 0);
  };
  int l = 0;
  for (int i = 0; i < n; ++i) {
    if (i > 0 && a[i] < a[i - 1]) {
      addSeg(l, i - 1);
      l = i;
    }
  }
  addSeg(l, n - 1);
  for (int qq = 0; qq < q; ++qq) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos, val;
      cin >> pos >> val;
      pos--;
      auto it = segs.lower_bound({pos, n});
      it--;
      int l = it->first;
      int r = it->second;
      a[pos] = val;
      if (pos > l && pos < r) {
        if (a[pos] < a[pos - 1]) {
          removeSeg(l, r);
          addSeg(l, pos - 1);
          addSeg(pos, r);
        } else if (a[pos] > a[pos + 1]) {
          removeSeg(l, r);
          addSeg(l, pos);
          addSeg(pos + 1, r);
        }
      } else {
        if (l == r) {
          if (l > 0 && a[pos] >= a[pos - 1]) {
            it--;
            int leftL = it->first;
            int leftR = it->second;
            removeSeg(leftL, leftR);
            removeSeg(l, l);
            addSeg(leftL, pos);
          } else if (r < n - 1 && a[pos] <= a[pos + 1]) {
            it++;
            int rightL = it->first;
            int rightR = it->second;
            removeSeg(l, l);
            removeSeg(rightL, rightR);
            addSeg(pos, rightR);
          }
        } else {
          if (pos == l) {
            if (l == 0) {
              if (a[l] > a[l + 1]) {
                removeSeg(l, r);
                addSeg(l + 1, r);
                addSeg(l, l);
              }
            } else {
              it--;
              int leftL = it->first;
              int leftR = it->second;
              if (a[l] >= a[l - 1] && a[l] <= a[l + 1]) {
                removeSeg(leftL, leftR);
                removeSeg(l, r);
                addSeg(leftL, r);
              } else if (a[l] >= a[l - 1]) {
                removeSeg(leftL, leftR);
                removeSeg(l, r);
                addSeg(leftL, l);
                addSeg(pos + 1, r);
              } else if (a[l] <= a[l + 1]) {
              } else {
                removeSeg(l, r);
                addSeg(l, l);
                addSeg(l + 1, r);
              }
            }
          } else {
            if (r == n - 1) {
              if (a[r] < a[r - 1]) {
                removeSeg(l, r);
                addSeg(l, r - 1);
                addSeg(r, r);
              }
            } else {
              it++;
              int rightL = it->first;
              int rightR = it->second;
              if (a[r] >= a[r - 1] && a[r] <= a[r + 1]) {
                removeSeg(rightL, rightR);
                removeSeg(l, r);
                addSeg(l, rightR);
              } else if (a[r] <= a[r + 1]) {
                removeSeg(rightL, rightR);
                removeSeg(l, r);
                addSeg(l, r - 1);
                addSeg(r, rightR);
              } else if (a[r] >= a[r - 1]) {
              } else {
                removeSeg(l, r);
                addSeg(r, r);
                addSeg(l, r - 1);
              }
            }
          }
        }
      }
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      auto it1 = segs.lower_bound({l, n});
      it1--;
      auto it2 = segs.lower_bound({r, n});
      it2--;
      int lLeft = it1->first;
      int rLeft = it1->second;
      int lRight = it2->first;
      int rRight = it2->second;
      long long totalSum = 0;
      if (lLeft != lRight) {
        totalSum = getSum(1, 0, n - 1, lLeft, lRight);
        totalSum -= f(rLeft - lLeft + 1, l - lLeft);
        totalSum -= f(rRight - lRight + 1, rRight - r);
      } else {
        totalSum = getSum(1, 0, n - 1, lLeft, lRight);
        totalSum -= f(rLeft - lLeft + 1, rLeft - lLeft + 1 - (r - l + 1));
      }
      cout << totalSum << "\n";
    }
  }
  return 0;
}

### Prompt

Your challenge is to write a CPP solution to the following problem:

Alice has recently received an array a_1, a_2, ..., a_n for her birthday! She is very proud of her array, and when she showed her friend Bob the array, he was very happy with her present too!

However, soon Bob became curious, and as any sane friend would do, asked Alice to perform q operations of two types on her array:

  * 1 x y: update the element a_x to y (set a_x = y). 
  * 2 l r: calculate how many non-decreasing subarrays exist within the subarray [a_l, a_{l+1}, ..., a_r]. More formally, count the number of pairs of integers (p,q) such that l ≤ p ≤ q ≤ r and a_p ≤ a_{p+1} ≤ ... ≤ a_{q-1} ≤ a_q. 



Help Alice answer Bob's queries!

Input

The first line contains two integers n and q (1 ≤ n, q ≤ 2 ⋅ 10^5) — the size of the array, and the number of queries, respectively.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9) — the elements of Alice's array.

The next q lines consist of three integers each. The first integer of the i-th line is t_i, the operation being performed on the i-th step (t_i = 1 or t_i = 2).

If t_i = 1, the next two integers are x_i and y_i (1 ≤ x_i ≤ n; 1 ≤ y_i ≤ 10^9), updating the element at position x_i to y_i (setting a_{x_i} = y_i).

If t_i = 2, the next two integers are l_i and r_i (1 ≤ l_i ≤ r_i ≤ n), the two indices Bob asks Alice about for the i-th query.

It's guaranteed that there is at least one operation of the second type.

Output

For each query of type 2, print a single integer, the answer to the query.

Example

Input


5 6
3 1 4 1 5
2 2 5
2 1 3
1 4 4
2 2 5
1 2 6
2 2 5


Output


6
4
10
7

Note

For the first query, l = 2 and r = 5, and the non-decreasing subarrays [p,q] are [2,2], [3,3], [4,4], [5,5], [2,3] and [4,5].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2e5;
long long t[4 * MaxN];
long long getSum(int v, int tl, int tr, int l, int r) {
  if (l > r) return 0;
  if (l == tl && r == tr) {
    return t[v];
  }
  int mid = (tl + tr) / 2;
  return getSum(v * 2, tl, mid, l, min(r, mid)) +
         getSum(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r);
}
void setVal(int v, int tl, int tr, int pos, long long val) {
  if (tl == tr) {
    t[v] = val;
    return;
  }
  int mid = (tl + tr) / 2;
  if (pos <= mid)
    setVal(v * 2, tl, mid, pos, val);
  else
    setVal(v * 2 + 1, mid + 1, tr, pos, val);
  t[v] = t[v * 2] + t[v * 2 + 1];
}
int a[MaxN];
long long f(long long totalLen, long long ignoredLen) {
  return ignoredLen * (ignoredLen + 1) / 2 +
         ignoredLen * (totalLen - ignoredLen);
}
int main(int argc, const char* argv[]) {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) cin >> a[i];
  set<pair<int, int>> segs;
  auto addSeg = [&](int l, int r) {
    segs.insert({l, r});
    int len = r - l + 1;
    setVal(1, 0, n - 1, l, len * 1ll * (len + 1) / 2);
  };
  auto removeSeg = [&](int l, int r) {
    segs.erase({l, r});
    setVal(1, 0, n - 1, l, 0);
  };
  int l = 0;
  for (int i = 0; i < n; ++i) {
    if (i > 0 && a[i] < a[i - 1]) {
      addSeg(l, i - 1);
      l = i;
    }
  }
  addSeg(l, n - 1);
  for (int qq = 0; qq < q; ++qq) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos, val;
      cin >> pos >> val;
      pos--;
      auto it = segs.lower_bound({pos, n});
      it--;
      int l = it->first;
      int r = it->second;
      a[pos] = val;
      if (pos > l && pos < r) {
        if (a[pos] < a[pos - 1]) {
          removeSeg(l, r);
          addSeg(l, pos - 1);
          addSeg(pos, r);
        } else if (a[pos] > a[pos + 1]) {
          removeSeg(l, r);
          addSeg(l, pos);
          addSeg(pos + 1, r);
        }
      } else {
        if (l == r) {
          if (l > 0 && a[pos] >= a[pos - 1]) {
            it--;
            int leftL = it->first;
            int leftR = it->second;
            removeSeg(leftL, leftR);
            removeSeg(l, l);
            addSeg(leftL, pos);
          } else if (r < n - 1 && a[pos] <= a[pos + 1]) {
            it++;
            int rightL = it->first;
            int rightR = it->second;
            removeSeg(l, l);
            removeSeg(rightL, rightR);
            addSeg(pos, rightR);
          }
        } else {
          if (pos == l) {
            if (l == 0) {
              if (a[l] > a[l + 1]) {
                removeSeg(l, r);
                addSeg(l + 1, r);
                addSeg(l, l);
              }
            } else {
              it--;
              int leftL = it->first;
              int leftR = it->second;
              if (a[l] >= a[l - 1] && a[l] <= a[l + 1]) {
                removeSeg(leftL, leftR);
                removeSeg(l, r);
                addSeg(leftL, r);
              } else if (a[l] >= a[l - 1]) {
                removeSeg(leftL, leftR);
                removeSeg(l, r);
                addSeg(leftL, l);
                addSeg(pos + 1, r);
              } else if (a[l] <= a[l + 1]) {
              } else {
                removeSeg(l, r);
                addSeg(l, l);
                addSeg(l + 1, r);
              }
            }
          } else {
            if (r == n - 1) {
              if (a[r] < a[r - 1]) {
                removeSeg(l, r);
                addSeg(l, r - 1);
                addSeg(r, r);
              }
            } else {
              it++;
              int rightL = it->first;
              int rightR = it->second;
              if (a[r] >= a[r - 1] && a[r] <= a[r + 1]) {
                removeSeg(rightL, rightR);
                removeSeg(l, r);
                addSeg(l, rightR);
              } else if (a[r] <= a[r + 1]) {
                removeSeg(rightL, rightR);
                removeSeg(l, r);
                addSeg(l, r - 1);
                addSeg(r, rightR);
              } else if (a[r] >= a[r - 1]) {
              } else {
                removeSeg(l, r);
                addSeg(r, r);
                addSeg(l, r - 1);
              }
            }
          }
        }
      }
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      auto it1 = segs.lower_bound({l, n});
      it1--;
      auto it2 = segs.lower_bound({r, n});
      it2--;
      int lLeft = it1->first;
      int rLeft = it1->second;
      int lRight = it2->first;
      int rRight = it2->second;
      long long totalSum = 0;
      if (lLeft != lRight) {
        totalSum = getSum(1, 0, n - 1, lLeft, lRight);
        totalSum -= f(rLeft - lLeft + 1, l - lLeft);
        totalSum -= f(rRight - lRight + 1, rRight - r);
      } else {
        totalSum = getSum(1, 0, n - 1, lLeft, lRight);
        totalSum -= f(rLeft - lLeft + 1, rLeft - lLeft + 1 - (r - l + 1));
      }
      cout << totalSum << "\n";
    }
  }
  return 0;
}

```