#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define crep(i,x,n) for(int i=x;i<n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define vec(...) vector<__VA_ARGS__>
#define _31av4qi ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
using pii=pair<int,int>;
using vi=vector<int>;
int sgn(int x){
return x>=0?1:-1;
}
ll f(vec(ll) a){
int n=sz(a);
vec(vec(ll)) dp(n,vec(ll)(2));
dp[0][0]=dp[0][1]=0;
rep(i,n-1){
ll d=a[i+1]-a[i];
dp[i+1][0]=max(dp[i+1][0],dp[i][0]+d);
dp[i+1][0]=max({dp[i+1][0],dp[i][1],dp[i][0]});
dp[i+1][1]=max(dp[i+1][1],dp[i][1]-d);
dp[i+1][1]=max({dp[i+1][1],dp[i][0],dp[i][1]});
}
return max(dp[n-1][0],dp[n-1][1]);
}
int main(){
_31av4qi;
int n;
cin>>n;
int q;
cin>>q;
vec(ll) a(n);
rep(i,n){
cin>>a[i];
}
rep(_,q){
int l,r,x;
cin>>l>>r>>x;
l--,r--;
crep(j,l,r+1) a[j]+=x;
cout<<f(a)<<"\n";
}
// ll ans=f(a);
// cout<<ans<<"\n";
//
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
7 |
Correct |
379 ms |
620 KB |
Output is correct |
8 |
Correct |
379 ms |
604 KB |
Output is correct |
9 |
Correct |
396 ms |
608 KB |
Output is correct |
10 |
Correct |
380 ms |
608 KB |
Output is correct |
11 |
Correct |
377 ms |
752 KB |
Output is correct |
12 |
Correct |
376 ms |
736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
7 |
Correct |
379 ms |
620 KB |
Output is correct |
8 |
Correct |
379 ms |
604 KB |
Output is correct |
9 |
Correct |
396 ms |
608 KB |
Output is correct |
10 |
Correct |
380 ms |
608 KB |
Output is correct |
11 |
Correct |
377 ms |
752 KB |
Output is correct |
12 |
Correct |
376 ms |
736 KB |
Output is correct |
13 |
Execution timed out |
2077 ms |
16920 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |