제출 #101541

#제출 시각아이디문제언어결과실행 시간메모리
101541jamielim케이크 (CEOI14_cake)C++14
15 / 100
2100 ms1672 KiB
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n,a;
    scanf("%d%d",&n,&a); a--;
    int arr[n];
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
    }
    int q;
    scanf("%d",&q);
    char op[5]; int x,y;
    for(int i=0;i<q;i++){
        scanf("%s%d",op,&x); x--;
        if(op[0]=='E'){
            scanf("%d",&y); y--;
            for(int j=0;j<n;j++){
                if(arr[j]>arr[x]&&arr[j]<=n-y){
                    arr[j]--;
                }
            }
            arr[x]=n-y;
        }else{
            if(a==x){
                printf("0\n");
                continue;
            }
            int l=a-1,r=a+1;
            int ans=1;
            while(l!=x&&r!=x){
                if(l==-1){r++; ans++;}
                else if(r==n){l--; ans++;}
                else if(arr[l]>arr[r]){
                    r++; ans++;
                }else if(arr[l]<arr[r]){
                    l--; ans++;
                }
            }
            if(l==x){
                while(r<n&&arr[l]>arr[r]){r++; ans++;}
            }else{
                while(l>=0&&arr[l]<arr[r]){l--;ans++;}
            }
            printf("%d\n",ans);
        }
    }
}

컴파일 시 표준 에러 (stderr) 메시지

cake.cpp: In function 'int main()':
cake.cpp:6:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&a); a--;
     ~~~~~^~~~~~~~~~~~~~
cake.cpp:9:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&arr[i]);
         ~~~~~^~~~~~~~~~~~~~
cake.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&q);
     ~~~~~^~~~~~~~~
cake.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s%d",op,&x); x--;
         ~~~~~^~~~~~~~~~~~~~
cake.cpp:17:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&y); y--;
             ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...