#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SS ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
// #pragma optimize("g", on)
// #pragma GCC optimize ("03")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
#define int long long
#define all(x) x.begin(),x.end()
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>, null_type,less_equal<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
const int LG = 20,N=1e6+1,inf=1e9,MOD=1e9+7;
const double eps = 1e-9;
int T;
int t[4*N],add[4*N];
void push(int v,int tl,int tr){
t[v]+=(tr-tl+1)*add[v];
if(tl<tr){
add[v*2]+=add[v];
add[v*2+1]+=add[v];
}
add[v]=0;
}
void upd(int v,int tl,int tr,int l,int r,int x){
push(v,tl,tr);
if(tl>r || l>tr) return;
if(tl>=l && r>=tr){
add[v]+=x;
push(v,tl,tr);
return;
}
int mid=(tl+tr)/2;
upd(v*2,tl,mid,l,r,x);
upd(v*2+1,mid+1,tr,l,r,x);
t[v]=t[v*2]+t[v*2+1];
}
int get(int v,int tl,int tr,int x){
push(v,tl,tr);
if(tl>tr) return 0;
if(tl==tr){
return t[v];
}
int mid=(tl+tr)/2;
if(mid>=x){
return get(v*2,tl,mid,x);
}
else{
return get(v*2+1,mid+1,tr,x);
}
}
void solve()
{
int n,m;
cin>>n>>m;
int h[n+1];
for(int i=1;i<=n;i++){
cin>>h[i];
if(i>1){
upd(1,1,N,min(h[i],h[i-1]),max(h[i],h[i-1]),1);
}
}
while(m--){
int t;
cin>>t;
if(t==1){
int pos,val;
cin>>pos>>val;
if(pos>1){
upd(1,1,N,min(h[pos],h[pos-1]),max(h[pos],h[pos-1]),-1);
// h[pos]=val;
upd(1,1,N,min(val,h[pos-1]),max(val,h[pos-1]),1);
}
if(pos<n){
upd(1,1,N,min(h[pos],h[pos+1]),max(h[pos],h[pos+1]),-1);
// h[pos]=val;
upd(1,1,N,min(val,h[pos+1]),max(val,h[pos+1]),1);
}
h[pos]=val;
}
else{
int H;
cin>>H;
cout<<get(1,1,N,H)<<'\n';
}
}
}
signed main()
{
SS
int t=1;
if(T){
cin>>t;
}
while(t--){
solve();
}
}
//5 1 4 2
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |