#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+5, MAXH = 1e6;
int bit[MAXH+5], h[MAXN];
void update(int i, int x){
for(; i <= MAXH; i += i&(-i))
bit[i] += x;
}
int query(int i){
int resp = 0;
for(; i > 0; i -= i&(-i))
resp += bit[i];
return resp;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n,m; cin>>n>>m;
for(int i = 1; i <= n; i++){
cin>>h[i];
if(i > 1){ update( min(h[i],h[i-1]), 1); update( max(h[i],h[i-1])+1, -1); }
}
for(int i = 1; i <= m; i++){
int t; cin>>t;
if(t == 1){
int pos,val; cin>>pos>>val;
if(pos < n){ update( min(h[pos],h[pos+1]), -1); update( max(h[pos],h[pos+1])+1, 1); }
if(pos > 1){ update( min(h[pos],h[pos-1]), -1); update( max(h[pos],h[pos-1])+1, 1); }
h[pos] = val;
if(pos < n){ update( min(h[pos],h[pos+1]), 1); update( max(h[pos],h[pos+1])+1, -1); }
if(pos > 1){ update( min(h[pos],h[pos-1]), 1); update( max(h[pos],h[pos-1])+1, -1); }
}else{
int x; cin>>x;
cout<<query(x)<<"\n";
}
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |