| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1069879 | n1k | Sjeckanje (COCI21_sjeckanje) | C++17 | 2071 ms | 11092 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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){
vector<ll> dp(n+1);
for(int i=0; i<n; i++){
ll mn=a[i], mx = a[i];
for(int j=i; j<n; j++){
mn = min(mn, a[j]);
mx = max(mx, a[j]);
dp[j+1]=max(dp[j+1], dp[i]+mx - mn);
}
}
return dp[n];
};
auto fast = [&](vector<ll> a){
vector<ll> d, dp(n+1);
for(int i=0; i+1<n; i++){
d.push_back(a[i+1] - a[i]);
}
for(int i=0; i<d.size(); i++){
// not pick
dp[i+1] = max(dp[i+1], dp[i]);
// pick
int sgn = (i+1 == d.size() ? 0 : signbit(d[i]) != signbit(d[i+1]));
dp[i+1+sgn] = max(dp[i+1+sgn], dp[i] + abs(d[i]));
}
return dp[d.size()];
};
while(q--){
ll l, r, add;
cin>>l>>r>>add;
l--, r--;
for(int i=l; i<=r;i++) a[i]+=add;
cout<<fast(a)<<endl;
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t=1; //cin >> t;
while(t--) solve();
}컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
