Submission #1278881

#TimeUsernameProblemLanguageResultExecution timeMemory
1278881Robert_juniorSjeckanje (COCI21_sjeckanje)C++20
110 / 110
454 ms29564 KiB
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3") #include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define int long long #define vecint vector <int> #define pb push_back #define all(v) (v).begin(), (v).end() #define R(i, j, k) for(int i = (j); i >= (k); i--) #define L(i, j, k) for(int i = (j); i <= (k); i++) const int N = 2e5 + 17; const int mod = 1e9 + 7; using namespace std; //using namespace __gnu_pbds; //template <typename T> //using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; /*struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } };*/ int dp[N * 4][2][2], L[N * 4], R[N * 4]; int a[N], b[N]; void f(int v, int l, int r) { int m = (l + r) >> 1; int x = v * 2, y = v * 2 + 1; L[v] = L[x]; R[v] = R[y]; for(auto i : {0, 1}){ for(auto j : {0, 1}){ dp[v][i][j] = 0; } } for(int i = 0; i < 2; i++){ for(int j = 0; j < 2; j++){ for(int k = 0; k < 2; k++){ for(int l = 0; l < 2; l++){ if(j && k){ if((R[x] < 0) == (L[y] < 0)){ dp[v][i][l] = max(dp[v][i][l], dp[x][i][j] + dp[y][k][l]); } } else{ dp[v][i][l] = max(dp[v][i][l], dp[x][i][j] + dp[y][k][l]); } } } } } } void upd(int v, int tl, int tr, int i, int val) { if(tl > i || tr < i) { return; } if(tl == tr) { L[v] += val; R[v] += val; dp[v][1][1] = abs(L[v]); return; } int m = (tl + tr) >> 1; upd(v + v, tl, m, i, val); upd(v + v + 1, m + 1, tr, i, val); f(v, tl, tr); } void solve(){ int n, q; cin >> n >> q; for(int i = 1; i <= n; i++){ cin>>a[i]; if(i >= 2){ upd(1, 1, n - 1, i - 1, a[i] - a[i - 1]); } } while(q--) { int l, r, x; cin >> l >> r >> x; if(l - 1 >= 1) upd(1, 1, n - 1, l - 1, x); if(r < n) upd(1, 1, n - 1, r, -x); cout<<dp[1][1][1]<<'\n'; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //freopen("ohwow.txt", "r", stdin); //freopen("superbull.out", "w", stdout); int tt = 1; //cin >> tt; while(tt--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...