Submission #197008

#TimeUsernameProblemLanguageResultExecution timeMemory
197008combi1k1Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
153 ms11640 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;

ll  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;
    ll  temp = 0;

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

    auto add = [&](int p,int x) {
        if (p == n) return;
        if (x == 0) return;

        temp -= 1ll * a[p] * (a[p] < 0 ? S : T);    a[p] += x;
        temp += 1ll * a[p] * (a[p] < 0 ? S : T);
    };

    for(int i = 0 ; i < n ; ++i)    {
        int x = a[i] - a[i + 1];    a[i] = 0;
        add(i,x);
    }
    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...