Submission #370321

#TimeUsernameProblemLanguageResultExecution timeMemory
370321TraduttoreSjeckanje (COCI21_sjeckanje)C++14
0 / 110
1 ms364 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define F first #define S second #define pb push_back #define ld long double #define int ll #define pll pair <ll,ll> #define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define TIME 1.0*clock()/CLOCKS_PER_SEC using namespace std; using namespace __gnu_pbds; mt19937_64 gen(time(0)); int n,q; vector <int> a; void init() { cin>>n>>q; a.resize(n); for (int i = 0;i < n;i++) cin>>a[i]; } ll ans = 0; void output() { cout<<ans<<'\n'; } int dp[(int)(1e6) ^ 1][(int)(2)]; void solve() { while (q--) { int l,r,x; cin>>l>>r>>x; --l; --r; for (int j = l;j <= r;j++) a[j]+=x; for (int i = 0;i < n;i++) { dp[i][1] = dp[i][0] = 0; } for (int i = 1;i < n;i++) { dp[i][1] = max(dp[i - 1][1],dp[i - 1][0] + abs(a[i] - a[i - 1])); dp[i][0] = max(dp[i - 1][0],dp[i - 1][1]); } ans = 0; for (int i = 0;i < n;i++) ans = max(ans,dp[i][1]); output(); } } int32_t main() { srand(time(0)); //freopen("adding.in","r",stdin); //freopen("adding.out","w",stdout); IOS; int test; test = 1; while (test--) { init(); solve(); } exit(0);} /*2 3 3 4*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...