#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];
void update( int i, int j, int s ) {
int l = min( h[i], h[j] ), r = max( h[i], h[j] );
aib.update( l, s );
aib.update( r + 1, -s );
}
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++ )
update( i, i + 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 )
update( p, p - 1, -1 );
if ( p < n )
update( p, p + 1, -1 );
h[p] = x;
if ( p > 1 )
update( p, p - 1, 1 );
if ( p < n )
update( p, p + 1, 1 );
} else {
int c;
cin >> c;
cout << aib.query( c );
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |