답안 #490537

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
490537 2021-11-27T21:33:17 Z inksamurai Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
1 ms 204 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (ll)a.size()
#define all(a) a.begin(),a.end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define crep(i,x,n) for(ll i=x;i<n;i++)
#define drep(i,n) for(ll 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<ll,ll>;
using vi=vector<ll>;

ll sgn(ll x){
	return x>=0?1:-1;
}

int main(){
_31av4qi;
	ll n,q;
	cin>>n>>q;
	vi a(n);
	rep(i,n){
		cin>>a[i];
	}
	vi _d(n);
	rep(cs,q){
		ll l,r,x;
		cin>>l>>r>>x;
		l--,r--;
		crep(i,l,r+1) a[i]+=x;
		crep(i,1,n) _d[i-1]=a[i]-a[i-1];
		ll ans=0;
		rep(i,n-1){
			if(sgn(_d[i])!=sgn(_d[i+1])){
				ans-=(ll)min(abs(_d[i]),abs(_d[i+1]));
			}
			ans+=(ll)abs(_d[i]);
		}	
		cout<<ans<<"\n";
	}
//	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -