This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 2e5;
int a[N + 1], n, q;
long long res, s, t;
struct FenwickTree
{
long long tree[N + 1];
void add(int pos, int val)
{
for (; pos <= n; pos |= pos + 1)
{
tree[pos] += val;
}
}
void add(int l, int r, int val)
{
add(l, val);
add(r + 1, - val);
}
long long get(int pos)
{
long long ret = a[pos];
for (; pos >= 0; pos = (pos & (pos + 1)) - 1)
{
ret += tree[pos];
}
return ret;
}
} tree;
void read()
{
cin >> n >> q >> s >> t;
for (int i = 0; i <= n; ++ i)
{
cin >> a[i];
if (i == 0)
{
continue;
}
if (a[i - 1] < a[i])
{
res += (a[i] - a[i - 1]) * s;
}
else
{
res -= (a[i - 1] - a[i]) * t;
}
}
}
long long val(int i)
{
long long x = tree.get(i), y = tree.get(i + 1);
if (x < y)
{
return (y - x) * s;
}
else
{
return (y - x) * t;
}
}
void solve()
{
while(q--)
{
int l, r, x;
cin >> l >> r >> x;
if (r < n)
{
res -= val(r);
}
res -= val(l - 1);
tree.add(l, r, x);
if (r < n)
{
res += val(r);
}
res += val(l - 1);
cout << -res << '\n';
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | freopen(TASK".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |