This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
Coded by thegamercoder
Happy Competition and Hacking
*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
#define FILER 0
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = pow(10, 9) + 7;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const ull INFUL = 0x3f3f3f3f3f3f3f3f;
const ll INFT = 0x3f3f3f3f;
const ll MAX = 401;
const ll MODD = 998244353;
const ll BL = 1;
const double EPS = 1e-10;
#define V vector
#define pll pair<ll, ll>
#define pull2 pair<ull,ull>
#define MS multiset
#define M map
#define Q queue
#define PQ priority_queue
#define IOF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define FOR(typ,i,a,b,c) for(typ i = a; i < b; i += c)
#define FORR(typ,i,a,b,c) for(typ i = a; i > b; i -= c)
#define FORA(a,i) for(auto i : a)
#define FORAE(a,i) for(auto &i : a)
#define all(v) v.begin(),v.end()
#define sorta(a) sort(all(a))
#define sortd(a) sort(all(a), greater<ll>())
#define setp(x) setprecision(x)<<fixed
#define RET return
#define log(a,b) log(b)/log(a)
#define WH(s) while(s)
#define WHI(t) WH(t--)
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define YESNO(s) cout<<(s?"YES":"NO")<<endl;
#define YesNo(s) cout<<(s?"Yes":"No")<<endl;
#define TYP 0
using namespace std;
ll n, q, s, t, l, r, x, tc, sc;
V<ll> a;
struct node
{
ll pf, sf, tc, sc;
};
node cmb(node a, node b)
{
node res = {};
res.pf = a.pf, res.sf = b.sf, res.tc = a.tc + b.tc, res.sc = a.sc + b.sc;
if (a.sf >= b.pf) res.tc += a.sf - b.pf;
else res.sc += b.pf - a.sf;
RET res;
}
V<node> st;
V<ll> lz;
void push(ll u, ll l, ll r)
{
st[u].pf += lz[u], st[u].sf += lz[u];
if (l != r) lz[u << 1] += lz[u], lz[u << 1 | 1] += lz[u];
lz[u] = 0;
}
void build(ll u, ll l, ll r)
{
if (l == r) { st[u].pf = st[u].sf = a[l]; RET; }
ll m = (l + r) >> 1;
build(u << 1, l, m); build(u << 1 | 1, m + 1, r);
st[u] = cmb(st[u << 1], st[u << 1 | 1]);
}
void upd(ll u, ll l, ll r, ll ql, ll qr, ll x)
{
push(u, l, r);
if (l > qr || ql > r)RET;
if (ql <= l && r <= qr)
{
lz[u] += x;
push(u, l, r);
RET;
}
ll m = (l + r) >> 1;
upd(u << 1, l, m, ql, qr, x); upd(u << 1 | 1, m + 1, r, ql, qr, x);
st[u] = cmb(st[u << 1], st[u << 1 | 1]);
}
void solve()
{
cin >> n >> q >> s >> t;
n++;
a.resize(n); st.resize(4 * n + 1); lz.resize(4 * n + 1);
FOR(ll, i, 0, n, 1)cin >> a[i];
build(1, 0, n - 1);
WHI(q)
{
cin >> l >> r >> x;
upd(1, 0, n - 1, l, r, x);
auto res = st[1];
cout << res.tc * t - res.sc * s << endl;
}
}
void init()
{
if (FILER)
{
freopen("pump.in", "r", stdin);
freopen("pump.out", "w", stdout);
}
}
void handle()
{
init();
ll t = 1;
if (TYP)cin >> t;
WHI(t)solve();
}
int main()
{
IOF
handle();
RET 0;
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'void init()':
foehn_phenomena.cpp:120:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
120 | freopen("pump.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:121:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
121 | freopen("pump.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |