Submission #1019544

# Submission time Handle Problem Language Result Execution time Memory
1019544 2024-07-11T03:25:50 Z aufan Distributing Candies (IOI21_candies) C++17
0 / 100
246 ms 34896 KB
#include "candies.h"
#include <bits/stdc++.h>

using namespace std;

const long long inf = 1e9;

struct node {
    long long val, lz, lb, ub;
    int st, en;
    node *left, *right;

    void build(int start, int end) {
        st = start;
        en = end;
        lz = 0;
        lb = -inf;
        ub = inf;

        if (st == en) {
            val = 0;
            return;
        }

        int md = (st + en) / 2;
        left = new node();
        right = new node();

        left->build(st, md);
        right->build(md + 1, en);
    }

    void lazy() {
        if (lz != 0) {
            left->val += lz;
            left->lz += lz;

            right->val += lz;
            right->lz += lz;

            lz = 0;
        }

        if (lb != -inf) {
            left->val = max(left->val, lb);
            left->lb = max(left->lb, lb);
            left->ub = max(left->ub, lb);
            left->val = min(left->val, ub);
            left->lb = min(left->lb, ub);
            left->ub = min(left->ub, ub);

            right->val = max(right->val, lb);
            right->lb = max(right->lb, lb);
            right->ub = max(right->ub, lb);
            right->val = min(right->val, ub);
            right->lb = min(right->lb, ub);
            right->ub = min(right->ub, ub);
        }

        lz = 0;
        lb = -inf;
        ub = inf;
    }

    long long query(int id) {
        if (st > id || en < id) return 0ll;
        if (st == en) return val;
        lazy();
        return left->query(id) + right->query(id);
    }

    void update(int lf, int rg, int x) {
        if (st > rg || en < lf) return;
        if (lf <= st && en <= rg) {
            val += lz;
            lz += x;
            return;
        }

        lazy();
        left->update(lf, rg, x);
        right->update(lf, rg, x);
    }

    void update2(int lf, int rg, long long x, long long y) {
        if (st > rg || en < lf) return;
        if (lf <= st && en <= rg) {
            val = max(val, x);
            lb = max(lb, x);
            ub = max(ub, x);
            
            val = min(val, y);
            lb = min(lb, y);
            ub = min(ub, y);

            lz = 0;
            return;
        }

        lazy();
        left->update2(lf, rg, x, y);
        right->update2(lf, rg, x, y);
    }
} sg;

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    int n = c.size(), q = (int)l.size();
    vector<int> s(n);
    sg.build(0, n - 1);
    for (int i = 0; i < q; i++) {
        sg.update(l[i], r[i], v[i]);
        sg.update2(0, n - 1, 0, c[0]);
    }

    for (int i = 0; i < n; i++) {
        s[i] = sg.query(i);
    }

    return s;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 246 ms 34896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -