Submission #386339

# Submission time Handle Problem Language Result Execution time Memory
386339 2021-04-06T12:06:59 Z phathnv Sjeckanje (COCI21_sjeckanje) C++11
0 / 110
1 ms 748 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];

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

struct Node{
    ll val, sum, leftVal, rightVal;
    Node(){
        val = sum = leftVal = rightVal = 0;
    }
    void update(ll delta){
        val += delta;
        sum = abs(val);
        leftVal = rightVal = val;
    }
    Node operator + (const Node &oth){
        Node res;
        res.leftVal = leftVal;
        res.rightVal = oth.rightVal;
        res.sum = sum + oth.sum;
        if (getSign(rightVal) * getSign(oth.leftVal) == -1)
            res.sum -= min(abs(rightVal), abs(oth.leftVal));
        return res;
    }
};

struct segmentTree{
    Node d[N * 4];
    void update(int id, int l, int r, int pos, int val){
        if (pos < l || r < pos)
            return;
        if (l == r){
            d[id].update(val);
            return;
        }
        int mid = (l + r) >> 1;
        update(id << 1, l, mid, pos, val);
        update(id << 1 | 1, mid + 1, r, pos, val);
        d[id] = d[id << 1] + d[id << 1 | 1];
    }
    ll solve(){
        return d[1].sum;
    }
} ST;

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

    cin >> n >> q;

    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i < n; i++)
        ST.update(1, 1, n - 1, i, a[i + 1] - a[i]);

    while (q--){
        int l, r, x;
        cin >> l >> r >> x;
        if (l > 1)
            ST.update(1, 1, n - 1, l - 1, x);
        if (r < n)
            ST.update(1, 1, n - 1, r, -x);
        cout << ST.solve() << '\n';
    }

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