Submission #937691

# Submission time Handle Problem Language Result Execution time Memory
937691 2024-03-04T11:01:47 Z vjudge1 Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
1 ms 348 KB
/* In the name of God */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
#define PB push_back
#define MP make_pair
#define all(a) (a).begin(), (a).end()
#define endl '\n'
#define dbg(x) cerr << '[' << #x << ": " << x << "]\n"
#define dbg2(x, y) cerr << '[' << #x << ": " << x << ", " << #y << ": " << y << "]\n"
#define YES cout << "YES\n"
#define NO cout << "NO\n"

const ll INF = (ll)2e18 + 1386;
const ld EPS = 0.000000000000001;
const int MOD = 1e9 + 7;

inline int _add(int a, int b){ int res = a + b; return (res >= MOD ? res - MOD : res); }
inline int _neg(int a, int b){ int res = (abs(a - b) < MOD ? a - b : (a - b) % MOD); return (res < 0 ? res + MOD : res); }
inline int _mlt(ll a, ll b){ return (a * b % MOD); }
inline void fileIO(string i, string o){ freopen(i.c_str(), "r", stdin); freopen(o.c_str(), "w", stdout); }

const int MAXN = 3e3 + 23;

ll dp[MAXN][2], a[MAXN], dif[MAXN];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++) cin >> a[i];
    while (q--){
        int l, r, x;
        cin >> l >> r >> x;
        for (int i = l; i <= r; i++) a[i] += x;
        for (int i = 2; i <= n; i++){
            dif[i] = a[i] - a[i - 1];
            if (i == 2){
                dp[i][0] = 0, dp[i][1] = abs(dif[i]);
                continue;
            }
            dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
            if ((dif[i] > 0 && dif[i - 1] < 0) || (dif[i] < 0 && dif[i - 1] > 0)) dp[i][1] = dp[i - 1][0] + abs(dif[i]);
            else dp[i][1] = dp[i - 1][1] + abs(dif[i]);
        }
        cout << max(dp[n][0], dp[n][1]) << endl;
    }
    return 0;
}

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -