Submission #950732

#TimeUsernameProblemLanguageResultExecution timeMemory
950732tnknguyen_Foehn Phenomena (JOI17_foehn_phenomena)C++14
30 / 100
1036 ms18256 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n' 

const int sz = 2e5 + 5;
vector<int> qr[sz];
long long a[sz];
int n, q, s, t;

// ------------ SUBTASKS ------------
namespace SUB1{
    bool ok(){
        return (n <= 2000 && q <= 2000);
    }

    void solve(){
        for(int i=1; i<=q; ++i){
            int l = qr[i][0], r = qr[i][1], x = qr[i][2];
            int ans = 0;
            for(int j=1; j<=n; ++j){
                if(j >= l && j <= r){
                    a[j] += x;
                }
                if(a[j-1] < a[j]){
                    ans -= (a[j] - a[j-1])*s;
                }
                else{
                    ans += (a[j-1] - a[j])*t;
                }
            }
            cout<<ans<<endl;
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //freopen("main.inp","r",stdin);
    //freopen("main.out","w",stdout);

    cin>>n>>q>>s>>t;
    for(int i=0; i<=n; ++i){
        cin>>a[i];
    }
    
    for(int i=1; i<=q; ++i){
        int l, r, x;
        cin>>l>>r>>x;
        qr[i] = {l, r, x};
    }

    SUB1::solve();

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...