Submission #1136141

#TimeUsernameProblemLanguageResultExecution timeMemory
1136141monaxiaSjeckanje (COCI21_sjeckanje)C++20
110 / 110
331 ms45596 KiB
#include <bits/stdc++.h> #define pb push_back #define ppb pop_back #define fr first #define sc second #define all(v) v.begin(), v.end() #define mod (long long)(1e9 + 7) #define eps (long long)(1e-9) #define vektor vector using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; const ull Mod = 1e9 + 7; const ll LIMIT = 2e5; struct node{ ll l, r, val00, val01, val10, val11; }; vector <node> st(8e5 + 5); node combine(node a, node b){ node ans = {a.l, b.r, 0, 0, 0, 0}; if(a.r * b.l >= 0){ ans.val00 = a.val01 + b.val10; ans.val01 = a.val01 + b.val11; ans.val10 = a.val11 + b.val10; ans.val11 = a.val11 + b.val11; ans.val01 = max(ans.val01, ans.val00); ans.val10 = max(ans.val10, ans.val00); ans.val11 = max(ans.val11, ans.val10); ans.val11 = max(ans.val11, ans.val01); } else{ ans.val00 = max(ans.val00, a.val00 + b.val10); ans.val00 = max(ans.val00, a.val01 + b.val00); ans.val01 = max(ans.val01, a.val00 + b.val11); ans.val01 = max(ans.val01, a.val01 + b.val01); ans.val10 = max(ans.val10, a.val10 + b.val10); ans.val10 = max(ans.val10, a.val11 + b.val00); ans.val11 = max(ans.val11, a.val10 + b.val11); ans.val11 = max(ans.val11, a.val11 + b.val01); ans.val01 = max(ans.val01, ans.val00); ans.val10 = max(ans.val10, ans.val00); ans.val11 = max(ans.val11, ans.val10); ans.val11 = max(ans.val11, ans.val01); } return ans; } void build(ll idx, ll l, ll r, vector <ll>& a, ll n){ if(l == r){ st[idx].l = st[idx].r = a[l]; st[idx].val11 = abs(a[l]); st[idx].val00 = st[idx].val01 = st[idx].val10 = 0; return; } ll mid = (l + r) >> 1; build(idx * 2, l, mid, a, n); build(idx * 2 + 1, mid + 1, r, a, n); st[idx] = combine(st[idx * 2], st[idx * 2 + 1]); // cout << l << " " << r << "\n" << st[idx * 2].r << ' ' << st[idx * 2 + 1].l << " " << st[idx].val << "\n"; } void update(ll idx, ll l, ll r, ll i, ll val){ if(l == r){ st[idx].l = st[idx].r = val; st[idx].val11 = abs(val); st[idx].val00 = st[idx].val01 = st[idx].val10 = 0; return; } ll mid = (l + r) >> 1; if(l <= i && i <= mid) update(idx * 2, l, mid, i, val); else update(idx * 2 + 1, mid + 1, r, i, val); st[idx] = combine(st[idx * 2], st[idx * 2 + 1]); } void solve(){ ll n, m, q; cin >> n >> q; m = n - 1; vector <ll> a(n + 1), d(n + 1), dp(n + 1, 0); for(ll i = 1; i <= n; i ++) cin >> a[i]; for(ll i = 1; i < n; i ++) d[i] = a[i + 1] - a[i]; build(1, 1, m, d, m); // cout << st[1].val11 << "\n"; while(q --){ ll l, r, val; cin >> l >> r >> val; d[l - 1] += val; d[r] -= val; if(l - 1 >= 1) update(1, 1, m, l - 1, d[l - 1]); if(r <= m) update(1, 1, m, r, d[r]); cout << st[1].val11 << "\n"; } } signed main() { cin.tie(0)->sync_with_stdio(0); // if(fopen("nameholder.inp", "r")){ // freopen("nameholder.inp", "r", stdin); // freopen("nameholder.out", "w", stdout); // } // cout << 1; return 0; ll n = 1; // cin >> n; while(n) { solve(); n --; cout << "\n"; } // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; } // ++++ // ++++-::......:--:::-=+++ // ++++=:............---.....--:..:=++++++ // +++++++::......................::=+++++ // @@ ++++++++++:+++++++++ // @% @* // %%@@ *****#*@@ // %%%%% @##**##***% // @@@@@@+-*#*@ #####%+*##*@ // %#+@%%@@@ ##-%:::-#*###@@ // =====:*::: ###-:==::=#*%* // -====:::::+@@%@@%@#*--=*#%%#@%@ @%@ // @=====%=-@%=:::.:+-::::+::::::::::::%-----%% @@@@@ // @@%#*@++%===+::-================@%@@@@+++++++@@@%%%@#%###% // @#***#@@ @##=%@===+--:+==+===+%*##@%%%@@@@@@@@@@:= @%@%%%@#%% // -@ @*#@ #####%:::-====+:::==---**%#@ *%%%%@@@@@@-: // -=-*% # #***--%%::::::::+=-+#-----=**@*# #+**#@# // ----=----#+****=----=*#@=::::::=#-----------***%*% // ------------%*****##=@==::::::+%-----------***%** // +-----------------*@++%::::::::-----------****@*# // =------------% @%=+%#+:::::::* #-----*--**** ** // ----%--% *==+++++=+=##*:% ---=--**** ** // %@@@@@@@@@==@+%%%%@ ----**** *# // @=*+%@@@%@@=++=:%:::% #***@@# // #+++++++++#==++-:::::: @**** *# // =+++++++++++==+++::::::: ####@ #% // +++++++++++=@ @++++::::::@ @# // @+++++++++=@ =*++=:::::@ // ++++++++@ @++++::::: // ++++++= =++++::: // =+++++@ =+++:::: // ++++++-@ =+++:+:: // @::+::::@ =++::-::: // +::=::::: @+*+:-+++-: // @::+-:::::# +++::::::@ // ::%=:::::::%@ @%++::::*** // @:+@*:::::::****@ +@+++:-=*:*@ // *:@@%::::::::=**** @%@+++:::#**@ // *%@@@-:::::::%=+==*@ +@%+++:***+* // #%@@%%::::::::#+=-=# =+@+++++:::*+ // @####+::::::::%+=@#%#=@ @**@@%=++::::@ // @ +:::::::::***#*@ @@###+=+=%@ +**#+=+*+:::- // =-:::::::%%%%@@ @#=*########%#+*%%+--@*+::% // +---%@ @@ =-:-**:# // %%%%% @+--*@ // @%%%%@ @%%%%% // @%%@@
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...