# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1032090 | LTTrungCHL | Sjeckanje (COCI21_sjeckanje) | C++17 | 2009 ms | 6492 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
///***LTT***///
/// ->NHAT QUOC GIA<- ///
#include<bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
//#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
using namespace std;
const long long oo = 1e9+7;
const int N = 2 * 1e5 + 10;
int n, q;
int a[N];
long long d[N], dp[N];;
void solve(){
cin >> n >> q;
for (int i = 1;i <= n;++i){
cin >> a[i];
}
for (int i = 1;i < n;++i){
d[i] = a[i] - a[i + 1];
}
for (int i = 1;i <= q;++i){
int l, r, x;
cin >> l >> r >> x;
for (int i = l;i <= r;++i){
a[i] += x;
}
d[l - 1] -= x;
d[r] += x;
for (int i = 1;i < n;++i){
if (d[i] * d[i - 1] < 0){
dp[i] = max(dp[i - 1], dp[i - 2] + abs(d[i]));
} else dp[i] = dp[i - 1] + abs(d[i]);
}
cout << dp[n - 1] <<"\n";
}
return;
}
int main(){
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
if (fopen("ltt.inp", "r")){
freopen("ltt.inp", "r", stdin);
freopen("ltt.out", "w", stdout);
}
// int t;
// cin >> t;
// while(t--){
solve();
// }
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |