/*
Author : DeMen100ns (a.k.a Vo Khac Trieu self-destruct)
School : VNU-HCM High school for the Gifted
*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
template<typename T> int SIZE(T (&t)){ return t.size(); } template<typename T, size_t N> int SIZE(T (&t)[N]){ return N; } string to_string(char t){ return "'" + string({t}) + "'"; } string to_string(bool t){ return t ? "true" : "false"; } string to_string(const string &t, int x1=0, int x2=1e9){ string ret = ""; for(int i = min(x1,SIZE(t)), _i = min(x2,SIZE(t)-1); i <= _i; ++i){ ret += t[i]; } return '"' + ret + '"'; } string to_string(const char* t){ string ret(t); return to_string(ret); } template<size_t N> string to_string(const bitset<N> &t, int x1=0, int x2=1e9){ string ret = ""; for(int i = min(x1,SIZE(t)); i <= min(x2,SIZE(t)-1); ++i){ ret += t[i] + '0'; } return to_string(ret); } template<typename T, typename... Coords> string to_string(const T (&t), int x1=0, int x2=1e9, Coords... C); template<typename T, typename S> string to_string(const pair<T, S> &t){ return "(" + to_string(t.first) + ", " + to_string(t.second) + ")"; } template<typename T, typename... Coords> string to_string(const T (&t), int x1, int x2, Coords... C){ string ret = "["; x1 = min(x1, SIZE(t)); auto e = begin(t); advance(e,x1); for(int i = x1, _i = min(x2,SIZE(t)-1); i <= _i; ++i){ ret += to_string(*e, C...) + (i != _i ? ", " : ""); e = next(e); } return ret + "]"; } template<int Index, typename... Ts> struct print_tuple{ string operator() (const tuple<Ts...>& t) { string ret = print_tuple<Index - 1, Ts...>{}(t); ret += (Index ? ", " : ""); return ret + to_string(get<Index>(t)); } }; template<typename... Ts> struct print_tuple<0, Ts...> { string operator() (const tuple<Ts...>& t) { return to_string(get<0>(t)); } }; template<typename... Ts> string to_string(const tuple<Ts...>& t) { const auto Size = tuple_size<tuple<Ts...>>::value; return print_tuple<Size - 1, Ts...>{}(t); } void dbgr(){;} template<typename Heads, typename... Tails> void dbgr(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgr(T...); } void dbgs(){;} template<typename Heads, typename... Tails> void dbgs(Heads H, Tails... T){ cout << H << " "; dbgs(T...); }
#define dbgv(...) cout << to_string(__VA_ARGS__) << endl;
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgv(__VA_ARGS__);
#define dbgr(...) dbgr(__VA_ARGS__); cout << endl;
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgr(__VA_ARGS__);
const int N = 2e5 + 5;
const long long INF = 1e18 + 7;
const int MAXA = 1e9;
const int B = sqrt(N) + 5;
int a[N], seg[4 * N], lazy[4 * N];
int n, s, t;
void down(int id){
int t = lazy[id];
seg[id << 1] += t;
seg[id << 1 | 1] += t;
lazy[id << 1] += t;
lazy[id << 1 | 1] += t;
lazy[id] = 0;
}
void upd(int id, int l, int r, int u, int v, int val){
if (l > v || r < u) return;
if (l >= u && r <= v){
seg[id] += val;
lazy[id] += val;
return;
}
down(id);
int mid = (l + r) >> 1;
upd(id << 1, l, mid, u, v, val);
upd(id << 1 | 1, mid + 1, r, u, v, val);
}
int get(int id, int l, int r, int pos){
if (l == r) return seg[id];
down(id);
int mid = (l + r) >> 1;
if (mid >= pos) return get(id << 1, l, mid, pos);
else return get(id << 1 | 1, mid + 1, r, pos);
}
int get_ans(int p){
if (p > n) return 0;
int v2 = get(1, 1, n, p);
int v1 = 0;
if (p > 1) v1 = get(1, 1, n, p - 1);
//dbgm(v1, v2);
if (v2 > v1) return -s * (v2 - v1);
else return t * (v1 - v2);
}
void solve(){
int q, ans = 0;
cin >> n >> q >> s >> t;
for(int i = 0; i <= n; ++i) cin >> a[i];
for(int i = 1; i <= n; ++i){
if (a[i] > a[i - 1]) ans -= s * (a[i] - a[i - 1]);
else ans += t * (a[i - 1] - a[i]);
}
for(int i = 1; i <= n; ++i) upd(1, 1, n, i, i, a[i]);
while (q--){
int l, r, v;
cin >> l >> r >> v;
ans -= get_ans(l);
ans -= get_ans(r + 1);
upd(1, 1, n, l, r, v);
ans += get_ans(l);
ans += get_ans(r + 1);
cout << ans << endl;
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen("codeforces.inp","r",stdin);
//freopen("codeforces.out","w",stdout);
int t = 1; //cin >> t;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
332 KB |
Output is correct |
2 |
Correct |
6 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
332 KB |
Output is correct |
4 |
Correct |
7 ms |
332 KB |
Output is correct |
5 |
Correct |
5 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
416 KB |
Output is correct |
7 |
Correct |
7 ms |
448 KB |
Output is correct |
8 |
Correct |
6 ms |
332 KB |
Output is correct |
9 |
Correct |
6 ms |
412 KB |
Output is correct |
10 |
Correct |
6 ms |
332 KB |
Output is correct |
11 |
Correct |
5 ms |
332 KB |
Output is correct |
12 |
Correct |
6 ms |
332 KB |
Output is correct |
13 |
Correct |
3 ms |
332 KB |
Output is correct |
14 |
Correct |
4 ms |
332 KB |
Output is correct |
15 |
Correct |
5 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
440 KB |
Output is correct |
17 |
Correct |
4 ms |
332 KB |
Output is correct |
18 |
Correct |
4 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
208 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
671 ms |
11444 KB |
Output is correct |
2 |
Correct |
669 ms |
12068 KB |
Output is correct |
3 |
Correct |
707 ms |
12816 KB |
Output is correct |
4 |
Correct |
668 ms |
11836 KB |
Output is correct |
5 |
Correct |
657 ms |
12596 KB |
Output is correct |
6 |
Correct |
399 ms |
13004 KB |
Output is correct |
7 |
Correct |
386 ms |
12924 KB |
Output is correct |
8 |
Correct |
647 ms |
13048 KB |
Output is correct |
9 |
Correct |
657 ms |
13320 KB |
Output is correct |
10 |
Correct |
717 ms |
11944 KB |
Output is correct |
11 |
Correct |
604 ms |
13088 KB |
Output is correct |
12 |
Correct |
456 ms |
13456 KB |
Output is correct |
13 |
Correct |
485 ms |
13828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
332 KB |
Output is correct |
2 |
Correct |
6 ms |
332 KB |
Output is correct |
3 |
Correct |
7 ms |
332 KB |
Output is correct |
4 |
Correct |
7 ms |
332 KB |
Output is correct |
5 |
Correct |
5 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
416 KB |
Output is correct |
7 |
Correct |
7 ms |
448 KB |
Output is correct |
8 |
Correct |
6 ms |
332 KB |
Output is correct |
9 |
Correct |
6 ms |
412 KB |
Output is correct |
10 |
Correct |
6 ms |
332 KB |
Output is correct |
11 |
Correct |
5 ms |
332 KB |
Output is correct |
12 |
Correct |
6 ms |
332 KB |
Output is correct |
13 |
Correct |
3 ms |
332 KB |
Output is correct |
14 |
Correct |
4 ms |
332 KB |
Output is correct |
15 |
Correct |
5 ms |
332 KB |
Output is correct |
16 |
Correct |
5 ms |
440 KB |
Output is correct |
17 |
Correct |
4 ms |
332 KB |
Output is correct |
18 |
Correct |
4 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
208 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
671 ms |
11444 KB |
Output is correct |
23 |
Correct |
669 ms |
12068 KB |
Output is correct |
24 |
Correct |
707 ms |
12816 KB |
Output is correct |
25 |
Correct |
668 ms |
11836 KB |
Output is correct |
26 |
Correct |
657 ms |
12596 KB |
Output is correct |
27 |
Correct |
399 ms |
13004 KB |
Output is correct |
28 |
Correct |
386 ms |
12924 KB |
Output is correct |
29 |
Correct |
647 ms |
13048 KB |
Output is correct |
30 |
Correct |
657 ms |
13320 KB |
Output is correct |
31 |
Correct |
717 ms |
11944 KB |
Output is correct |
32 |
Correct |
604 ms |
13088 KB |
Output is correct |
33 |
Correct |
456 ms |
13456 KB |
Output is correct |
34 |
Correct |
485 ms |
13828 KB |
Output is correct |
35 |
Correct |
661 ms |
11580 KB |
Output is correct |
36 |
Correct |
719 ms |
13076 KB |
Output is correct |
37 |
Correct |
675 ms |
13976 KB |
Output is correct |
38 |
Correct |
650 ms |
13604 KB |
Output is correct |
39 |
Correct |
723 ms |
13648 KB |
Output is correct |
40 |
Correct |
719 ms |
13608 KB |
Output is correct |
41 |
Correct |
689 ms |
13412 KB |
Output is correct |
42 |
Correct |
743 ms |
13516 KB |
Output is correct |
43 |
Correct |
740 ms |
12964 KB |
Output is correct |
44 |
Correct |
713 ms |
13416 KB |
Output is correct |
45 |
Correct |
682 ms |
13080 KB |
Output is correct |
46 |
Correct |
731 ms |
13724 KB |
Output is correct |
47 |
Correct |
391 ms |
13656 KB |
Output is correct |
48 |
Correct |
456 ms |
13860 KB |
Output is correct |
49 |
Correct |
639 ms |
12880 KB |
Output is correct |
50 |
Correct |
477 ms |
13720 KB |
Output is correct |
51 |
Correct |
398 ms |
13620 KB |
Output is correct |
52 |
Correct |
603 ms |
13592 KB |
Output is correct |