#include <bits/stdc++.h>
#define B17 ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define ll long long
#define debug(x) cout << #x << " = " << x << endl;
using namespace std;
const int maxn = 2e6 + 10;
int a[maxn] ,n , q;
ll ans;
int l , r, x;
bool cut[maxn];
void solve(){
cin >> l >> r >> x;
for(int i = l; i <= r; i++){
a[i] += x;
}
//for(int i = 1; i <= n; i++) cout << a[i] << endl;
ans = 0;
bool b_29 = false;
int b1 = 0;
for(int i = 1; i < n; i++){//***
ll jo1 = abs(a[i] - a[i - 1]) , jo2 = abs(a[i] - a[i + 1]);
if((i > 1) && ((a[i] < a[i + 1] && a[i] < a[i - 1] )|| (a[i] > a[i + 1] && a[i] > a[i - 1]))){ // dare ya tape
//cout << "slam mola" << i << endl;;
if(!b_29){
if(jo2 > jo1)
ans -= jo1;
ans += jo2;
b_29 = 1;
b1 = jo1;
// cout << "hi";
}
else{
if(jo2 > jo1){
ans -= jo1;
ans += b1;
ans += jo2;
}
// cout << "by";
b_29 = 0;
}
}
else {
b_29 = 0;
ans += jo2;
}
//debug(jo1); debug(jo2); debug(ans);
//cout << ans << " | " << endl;
}
cout << ans << endl ;
}
int main(){
B17;
cin >> n >> q;
for(int i = 1; i <= n; i++)cin >> a[i];
while(q--) solve();
}
/* temp
4 3
2 0 2 1
4 4 1
2 2 3
1 3 2
4 3
1 2 3 4
1 2 1
1 1 2
2 3 1
6 5
2 4 2 4 2 4
1 1 0
5 5
2 4 3 4 5
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |