Submission #593303

# Submission time Handle Problem Language Result Execution time Memory
593303 2022-07-10T20:10:18 Z LucaGreg Simple game (IZhO17_game) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

int sp[100010];
int h[100010];

int main()
{
    int n, m; scanf("%d %d", &n, &m);
    scanf("%d", &h[1]);
    for(int i=2;i<=n;i++){
        scanf("%d", &h[i]);
        sp[min(h[i-1], h[i])+1]++;
        sp[max(h[i-1], h[i])]--;
    }
    for(int i=1;i<sp.size();i++){
        sp[i] += sp[i-1];
    }
    for(int i=0;i<m;i++){
        int t; scanf("%d", &t);
        if(t==2){
            int hq; scanf("%d", &hq);
            printf("%d\n", sp[hq]);
        }else if(t==1){
            int pos, val; scanf("%d %d", &pos, &val);
            if(pos==1){
                for(int j=min(h[pos], h[pos+1])+1;j<max(h[pos], h[pos+1]);j++){
                    sp[j]--;
                }
                for(int j=min(val, h[pos+1])+1;j<max(val, h[pos+1]);j++){
                    sp[j]++;
                }
            }else if(pos==n){
                for(int j=min(h[pos], h[pos-1])+1;j<max(h[pos], h[pos-1]);j++){
                    sp[j]--;
                }
                for(int j=min(val, h[pos-1])+1;j<max(val, h[pos-1]);j++){
                    sp[j]++;
                }
            }else{
                for(int j=min(h[pos], h[pos+1])+1;j<max(h[pos], h[pos+1]);j++){
                    sp[j]--;
                }
                for(int j=min(h[pos], h[pos-1])+1;j<max(h[pos], h[pos-1]);j++){
                    sp[j]--;
                }
                for(int j=min(val, h[pos+1])+1;j<max(val, h[pos+1]);j++){
                    sp[j]++;
                }
                for(int j=min(val, h[pos-1])+1;j<max(val, h[pos-1]);j++){
                    sp[j]++;
                }
            }
        }
    }
    
    
    return 0;
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:18:22: error: request for member 'size' in 'sp', which is of non-class type 'int [100010]'
   18 |     for(int i=1;i<sp.size();i++){
      |                      ^~~~
game.cpp:11:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     int n, m; scanf("%d %d", &n, &m);
      |               ~~~~~^~~~~~~~~~~~~~~~~
game.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d", &h[1]);
      |     ~~~~~^~~~~~~~~~~~~
game.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%d", &h[i]);
      |         ~~~~~^~~~~~~~~~~~~
game.cpp:22:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         int t; scanf("%d", &t);
      |                ~~~~~^~~~~~~~~~
game.cpp:24:26: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |             int hq; scanf("%d", &hq);
      |                     ~~~~~^~~~~~~~~~~
game.cpp:27:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |             int pos, val; scanf("%d %d", &pos, &val);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~