#include <bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;
const int N = 30005;
ll a[N];
main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,m;
cin>>n>>m;
for (int i=1;i<=n;i++)
cin>>a[i];
while(m--){
int l,r,k;
cin>>l>>r>>k;
for (int i=l;i<=r;i++)
a[i] += k;
ll mn = a[1],mx=a[1],ans=0;
bool asc = 0,d=0;
for (int i=2;i<=n;i++){
if (a[i] > a[i - 1]){
if (d) {
ans += mx - mn;
mn = a[i],mx = a[i];
}
else{
mn = min(mn,a[i]);
mx = max(mx,a[i]);
}
asc=1,d=0;
}
else if (a[i] < a[i - 1]){
if (asc){
ans += mx - mn;
mn = a[i],mx = a[i];
}
else{
mn = min(mn,a[i]);
mx = max(mx,a[i]);
}
asc=0,d=1;
}
else d=asc=0,ans += mx - mn,mn = mx = a[i];
// cout<<ans<<" "<<asc<< " "<<d<<" "<<i<<endl;
}
if (asc) ans+= mx-mn;
if (d) ans+=mx-mn;
cout<<ans<<"\n";
}
}
Compilation message
Main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
7 | main (){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |