#include <bits/stdc++.h>
using namespace std;
struct AIB {
int n;
vector<int> aib;
void init( int _n ) {
n = _n;
aib.resize( n + 1 );
}
void update( int i, int x ) {
while ( i <= n ) {
aib[i] += x;
i += (i & -i);
}
}
int query( int i ) {
int s = 0;
while ( i > 0 ) {
s += aib[i];
i -= (i & -i);
}
return s;
}
} aib;
const int MAX_N = 1e5;
int h[MAX_N];
int main() {
int n, q;
cin >> n >> q;
for ( int i = 1; i <= n; i++ )
cin >> h[i];
aib.init( (int)1e6 + 1 );
for ( int i = 1; i < n; i++ ) {
int l = min( h[i], h[i + 1] ), r = max( h[i], h[i + 1] );
aib.update( l, 1 );
aib.update( r + 1, -1 );
}
for ( int i = 0; i < q; i++ ) {
int t;
cin >> t;
if ( t == 1 ) {
int p, x;
cin >> p >> x;
if ( p > 1 ) {
int l = min( h[p], h[p - 1] ), r = max( h[p], h[p - 1] );
aib.update( l, -1 );
aib.update( r + 1, 1 );
}
if ( p < n ) {
int l = min( h[p], h[p + 1] ), r = max( h[p], h[p + 1] );
aib.update( l, -1 );
aib.update( r + 1, 1 );
}
h[p] = x;
if ( p > 1 ) {
int l = min( h[p], h[p - 1] ), r = max( h[p], h[p - 1] );
aib.update( l, 1 );
aib.update( r + 1, -1 );
}
if ( p < n ) {
int l = min( h[p], h[p + 1] ), r = max( h[p], h[p + 1] );
aib.update( l, 1 );
aib.update( r + 1, -1 );
}
} else {
int h;
cin >> h;
cout << aib.query( h );
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |