답안 #1069255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069255 2024-08-21T18:13:48 Z n1k Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
1 ms 344 KB
#include <bits/stdc++.h>

#if defined(LOCAL)
#include "debug.cpp"
#else
#define debug(x...) 0
#endif // LOCAL

using namespace std;

using ll = long long;

#define all(a) (a).begin(), (a).end()

void solve(){
	int n, q; cin >> n >> q;
	vector<ll> a(n);
	for(int i=0; i<n; i++) cin >> a[i];
	auto get = [&](vector<ll> a){
		ll ans = 0;
		for(int i=0, j; i<n; i++){
			for(j=i; j<n-1 and a[i]<a[i+1] == a[j]<a[j+1]; j++){
			}
			if(a[j-1]==a[j]) j--;
			if(j==n-2) j++;
			ans+=abs(a[i]-a[j]);
			i=j;
		}
		return ans;
	};
	while(q--){
		ll l, r, add;
		cin>>l>>r>>add;
		l--, r--;
		for(int i=l; i<=r;i++) a[i]+=add;
		ll ans = get(a);
		reverse(all(a));
		ans = max(ans, get(a));
		reverse(all(a));
		cout<<ans<<endl;
	}
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int t=1; //cin >> t;
	while(t--) solve();
}

Compilation message

Main.cpp: In lambda function:
Main.cpp:22:27: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
   22 |    for(j=i; j<n-1 and a[i]<a[i+1] == a[j]<a[j+1]; j++){
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -