Submission #1067273

# Submission time Handle Problem Language Result Execution time Memory
1067273 2024-08-20T13:50:40 Z Zicrus Distributing Candies (IOI21_candies) C++17
27 / 100
222 ms 26448 KB
#include <bits/stdc++.h>
#include "candies.h"
using namespace std;

typedef long long ll;

struct node {
    ll offset;
    ll mn, mx;
};

ll n, q, cap;
ll pow2;
vector<node> seg;

void propagate(ll i) {
    seg[2*i].offset += seg[i].offset;
    seg[2*i].mn = clamp(seg[2*i].mn + seg[i].offset, seg[i].mn, seg[i].mx);
    seg[2*i].mx = clamp(seg[2*i].mx + seg[i].offset, seg[i].mn, seg[i].mx);
    seg[2*i+1].offset += seg[i].offset;
    seg[2*i+1].mn = clamp(seg[2*i+1].mn + seg[i].offset, seg[i].mn, seg[i].mx);
    seg[2*i+1].mx = clamp(seg[2*i+1].mx + seg[i].offset, seg[i].mn, seg[i].mx);
    seg[i] = {0, 0, cap};
}

void propagateRecursive(ll i = 1) {
    if (i >= pow2) return;
    propagate(i);
    propagateRecursive(2*i);
    propagateRecursive(2*i+1);
}

void update(ll low, ll high, ll val, ll nl = 0, ll nh = pow2-1, ll i = 1) {
    if (high < nl || low > nh) return;
    if (low <= nl && high >= nh) {
        seg[i].offset += val;
        seg[i].mn = clamp(seg[i].mn + val, 0ll, cap);
        seg[i].mx = clamp(seg[i].mx + val, 0ll, cap);
        return;
    }
    if (i >= pow2) return;
    propagate(i);
    update(low, high, val, nl, (nl+nh)/2, 2*i);
    update(low, high, val, (nl+nh)/2+1, nh, 2*i+1);
}

vector<int> distribute_candies(vector<int> c, vector<int> l,
                               vector<int> r, vector<int> v) {
    n = c.size(); q = v.size();
    cap = c[0];
    pow2 = 1ll << (ll)ceil(log2(n));
    seg = vector<node>(2*pow2, {0, 0, cap});
    for (int i = 0; i < q; i++) {
        update(l[i], r[i], v[i]);
    }
    propagateRecursive();

    vector<int> res(n);
    for (int i = 0; i < n; i++) {
        node &e = seg[pow2+i];
        res[i] = clamp(e.offset, e.mn, e.mx);
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 160 ms 19652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 101 ms 8028 KB Output is correct
3 Correct 39 ms 18244 KB Output is correct
4 Correct 197 ms 25716 KB Output is correct
5 Correct 222 ms 26032 KB Output is correct
6 Correct 190 ms 26448 KB Output is correct
7 Correct 168 ms 25644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -