Submission #592922

# Submission time Handle Problem Language Result Execution time Memory
592922 2022-07-09T20:05:18 Z hyakup Simple game (IZhO17_game) C++17
0 / 100
1000 ms 244 KB
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1000010;
int bit[maxn], height[maxn];

int n, m;

void update( int i, int v){
    
    for( int j = i; j <= n; j += j&-j) bit[j] += v; 
    
}


int query( int i ){
    
    int soma = 0;
    
    for (int j = i; j > 0; j -= j&-j) soma += bit[j];
    
    return soma;
}


int main()
{
    scanf("%d %d", &n, &m);
    
    
    for( int i = 1; i <= n; i++){
        scanf("%d", &height[i]);
    }
    
    for( int i = 1; i < n; i++){
        int top = max( height[i], height[i + 1]), bot = min( height[i], height[i + 1]);
        
        update( bot, 1 );
        update( top + 1, -1);
    }
    
    for( int i = 0; i < m; i++){
        
        int type; scanf("%d", &type);
        
        
        if( type == 1 ){
            int pos, val; scanf("%d %d", &pos, &val);
            
            int top, bot;
            
            if( pos < n ){
                top = max( height[i], height[i + 1]), bot = min( height[i], height[i + 1]);
                
                update( bot, -1 );
                update( top + 1, 1);
                
                top = max( val, height[i + 1]), bot = min( val, height[i + 1]);
                
                update( bot, 1 );
                update( top + 1, -1);
                
            }
            
            if( pos > 1 ){
                top = max( height[i], height[i - 1]), bot = min( height[i], height[i - 1]);
                
                update( bot, -1 );
                update( top + 1, 1);
                
                top = max( val, height[i - 1]), bot = min( val, height[i - 1]);
                
                update( bot, 1 );
                update( top + 1, -1);
                
            }
            
            height[pos] = val;
        }
        
        else{
            
            int h; scanf("%d", &h);    
            
            printf("%d\n", query(h));
        }
    }
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
game.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         scanf("%d", &height[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
game.cpp:52:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         int type; scanf("%d", &type);
      |                   ~~~~~^~~~~~~~~~~~~
game.cpp:56:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |             int pos, val; scanf("%d %d", &pos, &val);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~
game.cpp:91:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |             int h; scanf("%d", &h);
      |                    ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1097 ms 244 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1097 ms 244 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1097 ms 244 KB Time limit exceeded
3 Halted 0 ms 0 KB -