답안 #593306

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
593306 2022-07-10T20:15:16 Z LucaGreg Simple game (IZhO17_game) C++14
0 / 100
309 ms 4204 KB
#include <bits/stdc++.h>

using namespace std;

int sp[1000010];
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<1000010;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: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);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4160 KB Output is correct
2 Incorrect 309 ms 4204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4160 KB Output is correct
2 Incorrect 309 ms 4204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4160 KB Output is correct
2 Incorrect 309 ms 4204 KB Output isn't correct
3 Halted 0 ms 0 KB -