답안 #758272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758272 2023-06-14T10:55:31 Z Ronin13 Sjeckanje (COCI21_sjeckanje) C++14
0 / 110
9 ms 19028 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 200001;


struct node{
    ll dp[3];
    node(){
        for(int j= 0; j < 3; j++){
            for(int x = 0; x < 3; x++)
                dp[j] = -1e18;
        }
    }
}t[4 * nmax];

node merg(node a, node b){
    node c;
    for(int b1 = 0; b1 <= 2; b1++){
        for(int b2 = 0; b2 <= 2; b2++){
            int x = b1 + b2 - 2 + 1;
            c.dp[x] = max(c.dp[x], a.dp[b1] + b.dp[b2]);
        }
    }
    return c;
}

ll a[nmax];

void build(int v, int l, int r){
    if(l == r){
        t[v].dp[0] = -a[l];
        t[v].dp[1] = 0;
        t[v].dp[2] = a[l];
        return;
    }
    int m = (l + r) / 2;
    build(2 * v, l, m);
    build(2 * v + 1, m + 1, r);
    t[v] = merg(t[2 * v], t[2 * v + 1]);
    for(int j = 0; j < 3; j++){
        cout << t[v].dp[j] << ' ';
    }
    cout << "\n";
}

ll lazy[4 * nmax];

void push(int v){
    if(!lazy[v])
        return;
    t[v * 2].dp[0] -= lazy[v];
    t[ v * 2].dp[2] += lazy[v];
    t[v * 2 + 1].dp[0] -= lazy[v];
    t[v * 2 + 1].dp[2] += lazy[v];
    lazy[v * 2] += lazy[v];
    lazy[2 * v + 1] += lazy[v];
    lazy[v] =0;
}

void update(int v, int l, int r, int st, int fin, ll val){
    if(l > fin || r < st){
        return;
    }
    if(l >= st && r <= fin){
        t[v].dp[0] += -val;
        t[v].dp[2] += val;
        lazy[v] += val;
        return;
    }
    int m = (l + r) / 2;
    push(v);
    update(2 * v, l, m, st, fin, val);
    update(2 * v + 1, m + 1, r, st, fin, val);
    t[v] = merg(t[2 * v], t[2 * v + 1]);
}


int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    int q; cin >> q;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    build(1, 1, n);
   // cout << t[1].dp[1] << "\n";
    while(q--){
        int l, r, c; cin >> l >> r >> c;
        update(1,1, n, l, r, c);
        cout << t[1].dp[1] << "\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19028 KB Output isn't correct
2 Halted 0 ms 0 KB -