Submission #985931

#TimeUsernameProblemLanguageResultExecution timeMemory
985931LOLOLOSjeckanje (COCI21_sjeckanje)C++17
110 / 110
863 ms36312 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; #define f first #define s second #define pb push_back #define ep emplace #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin()) #define mem(f,x) memset(f , x , sizeof(f)) #define sz(x) (int)(x).size() #define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b)) #define mxx *max_element #define mnn *min_element #define cntbit(x) __builtin_popcountll(x) #define len(x) (int)(x.length()) const int N = 2e5 + 10; struct node{ ll f[2][2] = {0, 0, 0, 0}; ll st = 0, en = 0; } seg[N * 4]; int sign(ll a) { if (a == 0) return 0; if (a > 0) return 1; return -1; } void maximize(ll &a, ll b) { if (a < b) a = b; } node merge(node A, node B) { node C; C.st = A.st; C.en = B.en; for (int a = 0; a < 2; a++) { for (int b = 0; b < 2; b++) { for (int c = 0; c < 2; c++) { for (int d = 0; d < 2; d++) { if ((b & c) == 1 && sign(A.en) * sign(B.st) == 1) { maximize(C.f[a][d], A.f[a][b] + B.f[c][d]); } if ((b & c) == 0) { maximize(C.f[a][d], A.f[a][b] + B.f[c][d]); } } } } } return C; } void point(int id, int l, int r, int p, int add) { if (l > p || r < p) return; if (l == r) { seg[id].st += add; seg[id].en += add; seg[id].f[1][1] = abs(seg[id].st); return; } int m = (l + r) / 2; point(id * 2, l, m, p, add); point(id * 2 + 1, m + 1, r, p, add); seg[id] = merge(seg[id * 2], seg[id * 2 + 1]); } ll a[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; cin >> n >> q; for (int i = 1; i <= n; i++) { cin >> a[i]; if (i > 1) { point(1, 2, n, i, a[i] - a[i - 1]); } } for (int i = 1; i <= q; i++) { int l, r, x; cin >> l >> r >> x; if (l > 1) { point(1, 2, n, l, x); } if (r < n) { point(1, 2, n, r + 1, -x); } ll ans = 0; for (int a = 0; a < 2; a++) { for (int b = 0; b < 2; b++) { maximize(ans, seg[1].f[a][b]); } } cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...