Submission #1158501

#TimeUsernameProblemLanguageResultExecution timeMemory
1158501achiFoehn Phenomena (JOI17_foehn_phenomena)C++20
0 / 100
1093 ms2248 KiB
#include <bits/stdc++.h>

using namespace std;

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long int N, Q, S, T;
    long long int L, R, X;
    long long int i, j;
    long long int deg = 0;
    scanf("%lld %lld %lld %lld", &N, &Q, &S, &T);

    vector<long long int> altitiudes(N+1);

    for (i = 0; i < N+1; i++) {
        scanf("%lld", &altitiudes[i]);
        if (i == 0) continue;
        if (altitiudes[i-1] < altitiudes[i]) {
            deg += (altitiudes[i-1] - altitiudes[i])*S;
        }
        else {
            deg += (altitiudes[i-1] - altitiudes[i])*T;
        }
    }

    for (i = 0; i < Q; i++) {
        scanf("%lld %lld %lld", &L, &R, &X);
        if (L-1 >= 0) {
            if (altitiudes[L-1] < altitiudes[L]) {
                deg -= (altitiudes[L-1] - altitiudes[L])*S;
            }
            else {
                deg -= (altitiudes[L-1] - altitiudes[L])*T;
            }

            if (altitiudes[L-1] < (altitiudes[L] + X)) {
                deg += (altitiudes[L-1] - (altitiudes[L] + X))*S;
            }
            else {
                deg += (altitiudes[L-1] - (altitiudes[L] + X))*T;
            }
        }
        if (R+1 <= N) {
            if (altitiudes[R] < altitiudes[R+1]) {
                deg -= (altitiudes[R] - altitiudes[R+1])*S;
            }
            else {
                deg -= (altitiudes[R] - altitiudes[R+1])*T;
            }
            
            if ((altitiudes[R] + X) < altitiudes[R+1]) {
                deg += ((altitiudes[R] + X) - altitiudes[R+1])*S;
            }
            else {
                deg += ((altitiudes[R] + X) - altitiudes[R+1])*T;
            }
        }
        for (j = L; j <= R; j++) {
            altitiudes[j] += X;
        }
        printf("%d\n", deg);
    }

    return 0;
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:64:18: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   64 |         printf("%d\n", deg);
      |                 ~^     ~~~
      |                  |     |
      |                  int   long long int
      |                 %lld
foehn_phenomena.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%lld %lld %lld %lld", &N, &Q, &S, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%lld", &altitiudes[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%lld %lld %lld", &L, &R, &X);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...