Submission #386329

# Submission time Handle Problem Language Result Execution time Memory
386329 2021-04-06T11:54:03 Z phathnv Sjeckanje (COCI21_sjeckanje) C++11
55 / 110
575 ms 620 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 3007;
const ll INF = 1e18;

int n, q, a[N];
ll b[N], dp[N][2];

int getSign(ll x){
    if (x < 0)
        return -1;
    else if (x == 0)
        return 0;
    else
        return 1;
}

struct Node{
    ll dp[2][2], leftVal, rightVal;
    Node(int x = 0){
        dp[0][0] = 0;
        dp[1][1] = abs(x);
        dp[0][1] = dp[1][0] = -INF;
        leftVal = rightVal = x;
    }
    void update(ll delta){
        leftVal += delta;
        rightVal += delta;
    }
    Node operator + (const Node &oth){
        Node res;
        res.leftVal = leftVal;
        res.rightVal = oth.rightVal;
        for(int i = 0; i < 2; i++)
            for(int j = 0; j < 2; j++)
                res.dp[i][j] = -INF;
        for(int a = 0; a < 2; a++)
            for(int b = 0; b < 2; b++)
                for(int c = 0; c < 2; c++)
                    for(int d = 0; d < 2; d++){
                        ll val = dp[a][b] + oth.dp[c][d];
                        if (b && c && getSign(rightVal) * getSign(oth.leftVal) == -1)
                            val -= min(abs(rightVal), abs(oth.leftVal));
                        res.dp[a][d] = max(res.dp[a][d], val);
                    }
        return res;
    }
};

struct segmentTree{

};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> q;
    if (max(n, q) > 3000)
        return 0;

    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i < n; i++)
        b[i] = a[i + 1] - a[i];

    while (q--){
        int l, r, x;
        cin >> l >> r >> x;
        if (l > 1)
            b[l - 1] += x;
        if (r < n)
            b[r] -= x;
        Node res(b[1]);
        for(int i = 2; i < n; i++)
            res = res + Node(b[i]);
        cout << max(max(res.dp[0][0], res.dp[0][1]), max(res.dp[1][0], res.dp[1][1])) << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Correct 4 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 4 ms 364 KB Output is correct
6 Correct 4 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Correct 4 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 4 ms 364 KB Output is correct
6 Correct 4 ms 364 KB Output is correct
7 Correct 571 ms 492 KB Output is correct
8 Correct 559 ms 364 KB Output is correct
9 Correct 564 ms 364 KB Output is correct
10 Correct 563 ms 620 KB Output is correct
11 Correct 575 ms 568 KB Output is correct
12 Correct 528 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 5 ms 364 KB Output is correct
3 Correct 4 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 4 ms 364 KB Output is correct
6 Correct 4 ms 364 KB Output is correct
7 Correct 571 ms 492 KB Output is correct
8 Correct 559 ms 364 KB Output is correct
9 Correct 564 ms 364 KB Output is correct
10 Correct 563 ms 620 KB Output is correct
11 Correct 575 ms 568 KB Output is correct
12 Correct 528 ms 364 KB Output is correct
13 Incorrect 1 ms 364 KB Output isn't correct
14 Halted 0 ms 0 KB -