///***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 - 2] + d[j];
} 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();
//}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |