Submission #197005

#TimeUsernameProblemLanguageResultExecution timeMemory
197005combi1k1Foehn Phenomena (JOI17_foehn_phenomena)C++14
30 / 100
155 ms9848 KiB
#include<bits/stdc++.h>

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

int a[N];

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

    int n, q;   cin >> n >> q;
    int S, T;   cin >> S >> T;

    for(int i = 0 ; i <= n ; ++i)   cin >> a[i];
    for(int i = 1 ; i <= n ; ++i)   a[i - 1] -= a[i];

    ll  temp = 0;

    for(int i = 0 ; i < n ; ++i)
        temp += 1ll * a[i] * (a[i] > 0 ? T : S);

    auto add = [&](int p,int x) {
        if (p == n)
            return;
        temp -= 1ll * a[p] * (a[p] > 0 ? T : S);    a[p] += x;
        temp += 1ll * a[p] * (a[p] > 0 ? T : S);
    };

    for(int i = 0 ; i < q ; ++i)    {
        int l;  cin >> l;   --l;
        int r;  cin >> r;
        int x;  cin >> x;

        add(l,-x);
        add(r, x);

        cout << temp << "\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...