Submission #1024341

# Submission time Handle Problem Language Result Execution time Memory
1024341 2024-07-16T01:10:26 Z HappyCapybara Distributing Candies (IOI21_candies) C++17
0 / 100
735 ms 56040 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;

int n, k;
vector<vector<int>> st;

void merge(int node, vector<int> v){
    st[node][0] = max(0, min(k, st[node][0]+v[2]));
    st[node][1] = max(0, min(k, st[node][1]+v[2]));
    st[node][0] = max(st[node][0], v[0]);
    st[node][1] = min(st[node][1], v[1]);
    st[node][2] += v[2];
}

void prop(int node){
    merge(node*2, st[node]);
    merge(node*2+1, st[node]);
    st[node] = {0, k, 0};
}

void update(int l, int r, vector<int> v, int node=1, int tl=0, int tr=n-1){
    if (l <= tl && tr <= r){
        merge(node, v);
        return;
    }
    prop(node);
    int tm = (tl+tr)/2;
    if (l <= tm) update(l, r, v, node*2, tl, tm);
    if (tm+1 <= r) update(l, r, v, node*2+1, tm+1, tr);
}

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v){
    n = c.size();
    k = c[0];
    int q = l.size();
    st.resize(4*n, {0, k, 0});
    for (int i=0; i<q; i++) update(l[i], r[i], {max(0, min(k, v[i])), max(0, min(k, k-v[i])), v[i]});
    vector<int> s(n, 0);
    for (int i=0; i<n; i++){
        int cur = 1, tl = 0, tr = n-1;
        while (tl != tr){
            int tm = (tl+tr)/2;
            if (i <= tm){
                cur = cur*2;
                tr = tm;
            }
            else {
                cur = cur*2+1;
                tl = tm+1;
            }
        }
        while (cur){
            s[i] = max(st[cur][0], min(st[cur][1], s[i]+st[cur][2]));
            cur >>= 1;
        }
    }
    return s;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 735 ms 56040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -