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>
using namespace std;
const int N = 1e6 + 10;
int n, m, t[N], a[N];
void up( int idx, int va ) { for( int i = idx ; i < N ; i += i & -i ) t[i] += va; }
int query( int idx ) {
int ret = 0;
for( int i = idx ; i > 0 ; i -= i & -i ) ret += t[i];
return ret;
}
int main()
{
scanf("%d %d",&n,&m);
for( int i = 1 ; i <= n ; i++ ) scanf("%d",&a[i]);
for( int i = 1 ; i <= n ; i++ ) if( i < n ) up( min( a[i], a[i+1] ), 1 ), up( max( a[i], a[i+1] ), -1 );
while( m-- ) {
int t, i, h;
scanf("%d %d",&t,&i);
if( t == 1 ) {
scanf("%d",&h);
if( i > 1 ) up( min( a[i-1], a[i] ), -1 ), up( max( a[i-1], a[i] ), 1 );
if( i < n ) up( min( a[i], a[i+1] ), -1 ), up( max( a[i], a[i+1] ), 1 );
a[i] = h;
if( i > 1 ) up( min( a[i-1], a[i] ), 1 ), up( max( a[i-1], a[i] ), -1 );
if( i < n ) up( min( a[i], a[i+1] ), 1 ), up( max( a[i], a[i+1] ), -1 );
}
else printf("%d\n",query(i));
}
return 0;
}
Compilation message (stderr)
game.cpp: In function 'int main()':
game.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n,&m);
~~~~~^~~~~~~~~~~~~~~
game.cpp:17:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for( int i = 1 ; i <= n ; i++ ) scanf("%d",&a[i]);
~~~~~^~~~~~~~~~~~
game.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&t,&i);
~~~~~^~~~~~~~~~~~~~~
game.cpp:23:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&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... |