답안 #593311

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
593311 2022-07-10T20:34:29 Z LucaGreg Simple game (IZhO17_game) C++17
49 / 100
1000 ms 6800 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])]++;
        sp[max(h[i-1], h[i])+1]--;
    }
    for(int i=1;i<=1000001;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){
                //elimina a chain com o vertice seguinte
                for(int j=min(h[pos], h[pos+1]);j<=max(h[pos], h[pos+1]);j++){
                    sp[j]--;
                }
                //cria a chain(com a nova altura) com o vertice seguinte 
                for(int j=min(val, h[pos+1]);j<=max(val, h[pos+1]);j++){
                    sp[j]++;
                }
            }else if(pos==n){
                //elimina a chain com o vertice anterior 
                for(int j=min(h[pos], h[pos-1]);j<=max(h[pos], h[pos-1]);j++){
                    sp[j]--;
                }
                //cria a chain(com a nova altura) com o vertice anterior 
                for(int j=min(val, h[pos-1]);j<=max(val, h[pos-1]);j++){
                    sp[j]++;
                }
            }else{
                //elimina a chain com o vertice seguinte
                for(int j=min(h[pos], h[pos+1]);j<=max(h[pos], h[pos+1]);j++){
                    sp[j]--;
                }
                //elimina a chain com o vertice anterior 
                for(int j=min(h[pos], h[pos-1]);j<=max(h[pos], h[pos-1]);j++){
                    sp[j]--;
                }
                //cria a chain(com a nova altura) com o vertice seguinte 
                for(int j=min(val, h[pos+1]);j<=max(val, h[pos+1]);j++){
                    sp[j]++;
                }
                //cria a chain(com a nova altura) com o vertice anterior 
                for(int j=min(val, h[pos-1]);j<=max(val, h[pos-1]);j++){
                    sp[j]++;
                }
            }
            h[pos] = val;
        }
    }
    
    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 4176 KB Output is correct
2 Correct 378 ms 4204 KB Output is correct
3 Correct 368 ms 4204 KB Output is correct
4 Correct 340 ms 4200 KB Output is correct
5 Correct 378 ms 4204 KB Output is correct
6 Correct 336 ms 4200 KB Output is correct
7 Correct 5 ms 4304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4176 KB Output is correct
2 Correct 378 ms 4204 KB Output is correct
3 Correct 368 ms 4204 KB Output is correct
4 Correct 340 ms 4200 KB Output is correct
5 Correct 378 ms 4204 KB Output is correct
6 Correct 336 ms 4200 KB Output is correct
7 Correct 5 ms 4304 KB Output is correct
8 Correct 36 ms 5484 KB Output is correct
9 Correct 46 ms 6800 KB Output is correct
10 Correct 43 ms 6732 KB Output is correct
11 Correct 33 ms 5452 KB Output is correct
12 Correct 40 ms 6492 KB Output is correct
13 Correct 40 ms 6636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4176 KB Output is correct
2 Correct 378 ms 4204 KB Output is correct
3 Correct 368 ms 4204 KB Output is correct
4 Correct 340 ms 4200 KB Output is correct
5 Correct 378 ms 4204 KB Output is correct
6 Correct 336 ms 4200 KB Output is correct
7 Correct 5 ms 4304 KB Output is correct
8 Correct 36 ms 5484 KB Output is correct
9 Correct 46 ms 6800 KB Output is correct
10 Correct 43 ms 6732 KB Output is correct
11 Correct 33 ms 5452 KB Output is correct
12 Correct 40 ms 6492 KB Output is correct
13 Correct 40 ms 6636 KB Output is correct
14 Execution timed out 1089 ms 5596 KB Time limit exceeded
15 Halted 0 ms 0 KB -