#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define ld long double
#define int long long
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= b;i++)
#define per(i , a , b) for(int i=a;i >= b;i--)
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 5e5+ 10, K = 101, N = 1e6, inf = 1e9 + 1 , sq =280 , lg = 18, mod = 1e9+7 ;
int a[maxn] , val[maxn] ,n , q , ans = 0;
int ch(int v){
if(v>=n || v <=1)return 0 ;
if((val[v]>=0 && val[v-1]>=0) || (val[v]<=0 && val[v-1]<=0))return 0 ;
return -min(abs(val[v]) , abs(val[v-1]));
}
void upd(int v, int w){
ans -= ch(v) ;
ans -= ch(v+1) ;
ans -= abs(val[v]);
val[v] += w;
ans += abs(val[v]);
ans += ch(v) ;
ans += ch(v+1) ;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);
cin >> n >> q ;
rep(i , 1, n){
cin >> a[i] ;
if(i!=1)upd(i-1 , -a[i]) ;
if(i!=n)upd(i , a[i]) ;
}
while(q--){
int l , r , w ;
cin >> l >> r >> w ;
if(l!=1){
upd(l-1, -w) ;
}
if(r!=n){
upd(r , w) ;
}
cout << ans << "\n" ;
}
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |