#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define int long long
#define ll long long
#define pb push_back
#define fi first
#define se second
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
#define ld long double
using namespace std;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<int,pii> ipii;
typedef pair<pii,pii> ipiii;
const int MAXN = 1e6+10;
const int MAXA = 1e6;
const int INF = 1e18+10;
const int MOD = 1e9+7;
const int LOG = 32;
const ld EPS = 1e-12;
int n, m, a[MAXN];
struct seg {
    int st[2*MAXN];
    int que(int x){
        int te = 0;
        for(;x>=1; x-=(x&(-x))) te += st[x];
        return te;
    }
    void upd(int x, int y){
        for(;x<=2*MAXN-20;x+=(x&(-x))) 
            st[x] += y;
    }
} A;
void UPD(int x, int y){
    if(x!=1){
        A.upd(min(a[x],a[x-1]), y);
        A.upd(max(a[x],a[x-1])+1, -y);
    } 
    if(x!=n){
        A.upd(min(a[x],a[x+1]), y);
        A.upd(max(a[x],a[x+1])+1, -y);
    } 
}
signed main(){
    // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=2; i<=n; i++){
        A.upd(min(a[i],a[i-1]), 1);
        A.upd(max(a[i],a[i-1])+1, -1);
    }
    for(int i=1; i<=m; i++){
        int ty; cin >> ty;
        if(ty==2){
            int x; cin >> x;
            cout << A.que(x) << '\n';
        } else {
            int id, x; cin >> id >> x;
            UPD(id, -1);
            a[id] = x;
            UPD(id, 1);
        }
    }
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |