This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
using namespace std;
using ll = long long;
using pii = pair <int, int>;
const int maxN = 2e5 + 10;
const int inf = 0x3f3f3f3f;
//const int Mod =
int n, q, s, t;
int a[maxN];
struct TNode{
ll val, l, r, lazy;
TNode(){
val = l = r = lazy = 0;
}
TNode(ll _val, int _l, int _r, int _lazy){
val = _val;
l = _l;
r = _r;
lazy = _lazy;
}
TNode(TNode x, TNode y){
l = x.l;
r = y.r;
lazy = 0;
val = x.val + y.val;
if (x.r < y.l) val -= 1LL * (y.l - x.r) * s;
else val += 1LL * (x.r - y.l) * t;
}
};
TNode st[maxN * 4];
void push(int id){
if (st[id].lazy){
st[id << 1].lazy += st[id].lazy;
st[id << 1 | 1].lazy += st[id].lazy;
st[id << 1].l += st[id].lazy;
st[id << 1].r += st[id].lazy;
st[id << 1 | 1].l += st[id].lazy;
st[id << 1 | 1].r += st[id].lazy;
st[id].lazy = 0;
}
}
void build(int id = 1, int l = 1, int r = n){
if (l == r){
st[id] = {0, a[l], a[l], 0};
return;
}
int mid = (l + r) >> 1;
build(id << 1, l, mid);
build(id << 1 | 1, mid + 1, r);
st[id] = TNode(st[id << 1], st[id << 1 | 1]);
}
void update(int id, int i, int j, int x, int l = 1, int r = n){
if (i > r || l > j) return;
if (i <= l && r <= j){
st[id].l += x;
st[id].r += x;
st[id].lazy += x;
return;
}
int mid = (l + r) >> 1;
push(id);
update(id << 1, i, j, x, l, mid);
update(id << 1 | 1, i, j, x, mid + 1, r);
st[id] = TNode(st[id << 1], st[id << 1 | 1]);
}
void Init(){
cin >> n >> q >> s >> t;
++n;
for (int i = 1; i <= n; ++i) cin >> a[i];
build();
for (int i = 1; i <= q; ++i){
int l, r, x;
cin >> l >> r >> x;
update(1, l + 1, r + 1, x);
cout << st[1].val << "\n";
}
}
#define taskname "test"
signed main(){
faster
if (fopen(taskname ".inp", "r")){
freopen(taskname ".inp", "r", stdin);
freopen(taskname ".out", "w", stdout);
}
int tt = 1;
//cin >> tt;
while (tt--){
Init();
}
if (fopen("timeout.txt", "r")){
ofstream timeout("timeout.txt");
cerr << "Time elapsed: " << signed(double(clock()) / CLOCKS_PER_SEC * 1000) << "ms\n";
timeout << signed(double(clock()) / CLOCKS_PER_SEC * 1000);
timeout.close();
}
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
94 | freopen(taskname ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
95 | freopen(taskname ".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... |