Submission #152798

#TimeUsernameProblemLanguageResultExecution timeMemory
152798HideoFoehn Phenomena (JOI17_foehn_phenomena)C++14
0 / 100
164 ms5472 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >

const int N = 2e5 + 7;
const int INF = 1e9 + 7;

ll a[N], val[N], ans;
int n, q, s, t;

main(){
    cin >> n >> q >> s >> t;
    for (int i = 0; i <= n; i++){
        scanf("%lld", &a[i]);
        if (i && a[i] > a[i - 1])
            val[i] = (a[i - 1] - a[i]) * s;
        else if (i)
            val[i] = (a[i - 1] - a[i]) * t;
        ans += val[i];
    }
    while (q--){
        ll l, r, x;
        scanf("%lld%lld%lld", &l, &r, &x);
        a[l] += x;
        a[r] += x;
        r++;
        ans -= (val[l] + val[r]);
        if (a[l] > a[l - 1])
            val[l] = (a[l - 1] - a[l]) * s;
        else
            val[l] = (a[l - 1] - a[l]) * t;
        if (r <= n){
            if (a[r] > a[r - 1])
                val[r] = (a[r - 1] - a[r]) * s;
            else
                val[r] = (a[r - 1] - a[r]) * t;
        }
        ans += (val[l] + val[r]);
        printf("%lld\n", ans);
    }
}

Compilation message (stderr)

foehn_phenomena.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &a[i]);
         ~~~~~^~~~~~~~~~~~~~~
foehn_phenomena.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         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...