Submission #870133

#TimeUsernameProblemLanguageResultExecution timeMemory
870133LTTrungCHLSjeckanje (COCI21_sjeckanje)C++17
0 / 110
2 ms4444 KiB
///***LTT***/// /// ->NHAT QUOC GIA<- /// #include<bits/stdc++.h> //#pragma GCC optimize ("O3") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("popcnt") //#define int long long #define endl "\n" #define F first #define S second #define pb push_back using namespace std; const long long oo = 1e9+7; const int N = 2 * 1e5 + 10; int n, q; long long a[N], d[N], dp[N]; long long l, r, x; void inp(){ cin >> n >> q; for (int i = 1;i <= n;i++){ cin >> a[i]; } return; } void solve(){ for (int i = 1;i <= q;i++){ cin >> l >> r >> x; for (int j = l;j <= r;j++){ a[j] += x; } for (int j = 1;j < n;j++){ dp[j] = 0; d[j] = abs(a[j] - a[j + 1]); } long long ans = 0; for (int j = 1;j < n;j++){ if ( (a[j - 1] - a[j]) * (a[j] - a[j + 1]) < 0 and j >= 2 ){ dp[j] = dp[j - 1]; } else dp[j] = dp[j - 1] + d[j]; // cout << j <<" "<< dp[j] <<"\n"; ans = max(ans, dp[j]); } cout << ans <<"\n"; } return; } int main(){ ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); // if (fopen("file.inp", "r")){ // freopen("file.inp", "r", stdin); // freopen("file.out", "w", stdout); // } //int t; //cin >> t; //while(t--){ inp(); solve(); //} }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...