이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |