This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define int long long
# define fi first
# define se second
using namespace std;
const int N = 1e6 + 7;
const int mod = 1e9 + 7;
int a[N], t[4 * N];
void upd( int v, int l, int r, int pos, int add ) {
if ( l == r ) {
t[v] += add;
return;
}
int m = (l + r) / 2;
if ( pos <= m ) {
upd( v * 2, l, m, pos, add );
}
else {
upd( v * 2 + 1, m + 1, r, pos, add );
}
t[v] = t[v * 2] + t[v * 2 + 1];
}
int get( int v, int tl, int tr, int l, int r ) {
if ( l > r ) {
return 0;
}
if ( tl == l && tr == r ) {
return t[v];
}
int m = (tl + tr) / 2;
int sm = get( v * 2, tl, m, l, min( r, m ) );
sm += get( v * 2 + 1, m + 1, tr, max( l, m + 1 ), r );
return sm;
}
int32_t main() {
speed;
int n, m;
cin >> n >> m;
for ( int i = 1; i <= n; i++ ) {
cin >> a[i];
}
int MAXN = 1e6;
for ( int i = 2; i <= n; i++ ) {
int l = a[i - 1], r = a[i];
if ( l > r ) {
swap( l, r );
}
// dp[l]++;
upd( 1, 1, MAXN, l, 1 );
upd( 1, 1, MAXN, r + 1, -1 );
// dp[r + 1]--;
}
for ( int i = 1; i <= m; i++ ) {
int t;
cin >> t;
if ( t == 2 ) {
int h, cnt = 0;
cin >> h;
cout << get( 1, 1, MAXN, 1, h ) << '\n';
}
else {
int pos, val;
cin >> pos >> val;
if ( pos != 1 ) {
int l = a[pos - 1], r = a[pos];
if ( l > r ) {
swap( l, r );
}
upd( 1, 1, MAXN, l, -1 );
upd( 1, 1, MAXN, r + 1, 1 );
}
if ( pos != n ) {
int l = a[pos], r = a[pos + 1];
if ( l > r ) {
swap( l, r );
}
upd( 1, 1, MAXN, l, -1 );
upd( 1, 1, MAXN, r + 1, 1 );
}
a[pos] = val;
if ( pos != 1 ) {
int l = a[pos - 1], r = a[pos];
if ( l > r ) {
swap( l, r );
}
upd( 1, 1, MAXN, l, 1 );
upd( 1, 1, MAXN, r + 1, -1 );
}
if ( pos != n ) {
int l = a[pos], r = a[pos + 1];
if ( l > r ) {
swap( l, r );
}
upd( 1, 1, MAXN, l, 1 );
upd( 1, 1, MAXN, r + 1, -1 );
}
}
}
}
Compilation message (stderr)
game.cpp: In function 'int32_t main()':
game.cpp:64:20: warning: unused variable 'cnt' [-Wunused-variable]
64 | int h, cnt = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |