Submission #1069362

# Submission time Handle Problem Language Result Execution time Memory
1069362 2024-08-21T20:22:11 Z Boas Distributing Candies (IOI21_candies) C++17
0 / 100
71 ms 32336 KB
#include "candies.h"

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vi;
typedef vector<signed> vi32;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef set<int> si;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pb push_back
#define loop(x, i) for (int i = 0; i < x; i++)
#define rev(x, i) for (int i = (int)x - 1; i >= 0; i--)
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define sz(x) (int)x.size()

vi32 distribute_candies(vi32 c, vi32 l, vi32 r, vi32 v)
{
    int n = sz(c);
    int q = sz(l);

    vi32 s(n);
    vi sufSum(n + 1);
    vi sufMax(n + 1);
    vi sufMin(n + 1);
    vi diff(n + 1);
    // map<int,int> lastIx;
    rev(q, j)
    {
        assert(n - 1 == r[j]);
        sufSum[j] = sufSum[j + 1] + v[j];
        sufMin[j] = min(sufMin[j + 1], sufSum[j]);
        sufMax[j] = max(sufMax[j + 1], sufSum[j]);
        diff[j] = sufMax[j] - sufMin[j];
    }
    loop(n, i)
    {
        int ix = n - (lower_bound(RALL(diff), c[i]) - diff.rbegin());
        if (ix == -1)
        {
            s[i] = sufSum[0];
            continue;
        }
        if (sufSum[ix] == sufMax[ix])
        {
            int mn = sufMin[ix];
            int mnIx = upper_bound(ALL(sufMin), mn) - sufMin.begin() - 1;
            s[i] = c[i] + sufSum[mnIx];
        }
        else
        {
            int mx = sufMax[ix];
            int mxIx = n - (lower_bound(RALL(sufMax), mx) - sufMax.rbegin());
            s[i] = sufSum[mxIx];
        }
    }
    return s;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1 ms 600 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 71 ms 32336 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 38 ms 12880 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1 ms 600 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -