답안 #233458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
233458 2020-05-20T14:56:08 Z DodgeBallMan Simple game (IZhO17_game) C++14
100 / 100
101 ms 6952 KB
#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

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);
             ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 7 ms 4096 KB Output is correct
3 Correct 7 ms 4096 KB Output is correct
4 Correct 7 ms 4096 KB Output is correct
5 Correct 7 ms 4096 KB Output is correct
6 Correct 7 ms 4096 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 7 ms 4096 KB Output is correct
3 Correct 7 ms 4096 KB Output is correct
4 Correct 7 ms 4096 KB Output is correct
5 Correct 7 ms 4096 KB Output is correct
6 Correct 7 ms 4096 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 54 ms 1784 KB Output is correct
9 Correct 68 ms 6904 KB Output is correct
10 Correct 66 ms 6916 KB Output is correct
11 Correct 55 ms 1656 KB Output is correct
12 Correct 61 ms 2808 KB Output is correct
13 Correct 58 ms 2808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 7 ms 4096 KB Output is correct
3 Correct 7 ms 4096 KB Output is correct
4 Correct 7 ms 4096 KB Output is correct
5 Correct 7 ms 4096 KB Output is correct
6 Correct 7 ms 4096 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 54 ms 1784 KB Output is correct
9 Correct 68 ms 6904 KB Output is correct
10 Correct 66 ms 6916 KB Output is correct
11 Correct 55 ms 1656 KB Output is correct
12 Correct 61 ms 2808 KB Output is correct
13 Correct 58 ms 2808 KB Output is correct
14 Correct 85 ms 6904 KB Output is correct
15 Correct 101 ms 6952 KB Output is correct
16 Correct 85 ms 6904 KB Output is correct
17 Correct 87 ms 6904 KB Output is correct
18 Correct 87 ms 6904 KB Output is correct