//In The Name Of ALLAH!
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds;
using namespace std;
 
#define ll long long
#define ld long double
#define endl '\n'
#define pb push_back
#define pf push_front
#define Zemur007 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define bpc __builtin_popcountll
#define btz __builtin_ctzll
#define all(x) x.begin() , x.end()
#define allr(x) x.rbegin() , x.rend()
#define F first
#define S second
#define pll pair<ll , ll>
#define turtle tuple<ll , ll , ll>
#define pss pair<string , string>
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define indexed_set tree<pll , null_type , less<pll> , rb_tree_tag , tree_order_statistics_node_update>
void open(){
    freopen("game.in" , "r" , stdin);
    freopen("game.out" , "w" , stdout);
}
const ll sz = 1e5 + 5 , INF = 1e18 ,  MOD = 1e9 + 7;
ll a[sz] , op[sz] , ind[sz] , val[sz] , ask[sz];
struct Fenwick{
    vector<ll> ft;
    Fenwick(ll n){
        ft.assign(n + 1 , 0);
    }
    void update(ll n , ll x , ll val){
        for(ll i = x ; i <= n ; i += i & -i) ft[i] += val;
    }
    ll get(ll x){
        ll ans = 0;
        for(ll i = x ; i > 0 ; i -= i & -i) ans += ft[i];
        return ans;
    }
    ll query(ll l , ll r){
        return get(r) - get(l - 1);
    }
};
ll mask , i , j , k;
void solve(){
    ll n , q , m = 0; cin >> n >> q;
    for(i = 1 ; i <= n ; i++) cin >> a[i] , m = max(m , a[i]);
    for(i = 1 ; i <= q ; i++){
        cin >> op[i];
        if(op[i] == 1){
            cin >> ind[i] >> val[i];
            m = max(m , val[i]);
        }
        else{
            cin >> ask[i];
            m = max(m , val[i]);
        }
    }
    Fenwick ft(m + 5);
    for(i = 2 ; i <= n ; i++){
        ft.update(m , min(a[i] , a[i - 1]) + 1 , 1);
        ft.update(m , max(a[i] , a[i - 1]) , -1);
    }
    for(i = 1 ; i <= q ; i++){
        if(op[i] == 1){
            if(ind[i] - 1 >= 1){
                ft.update(m , min(a[ind[i] - 1] , a[ind[i]]) + 1 , -1);
                ft.update(m , max(a[ind[i] - 1] , a[ind[i]]) , 1);
                ft.update(m , min(a[ind[i] - 1] , val[i]) + 1 , 1);
                ft.update(m , max(a[ind[i] - 1] , val[i]) , -1);
            }
            if(ind[i] + 1 <= n){
                ft.update(m , min(a[ind[i] + 1] , a[ind[i]]) + 1 , -1);
                ft.update(m , max(a[ind[i] + 1] , a[ind[i]]) , 1);
                ft.update(m , min(a[ind[i] + 1] , val[i]) + 1 , 1);
                ft.update(m , max(a[ind[i] + 1] , val[i]) , -1);
            }
            a[ind[i]] = val[i];
        }
        else{
            cout << ft.get(ask[i]) << endl;
        }
    }
}     
 
signed main(){
    Zemur007;
    open;
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    // for(ll testcase = 1 ; testcase <= t ; testcase++){
    //     cout << "Case " << testcase << ":" << endl;
    //     solve();
    // }
}
Compilation message (stderr)
game.cpp: In function 'void open()':
game.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("game.in" , "r" , stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:31:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     freopen("game.out" , "w" , stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |