Submission #535758

# Submission time Handle Problem Language Result Execution time Memory
535758 2022-03-11T06:43:09 Z KoD Distributing Candies (IOI21_candies) C++17
0 / 100
99 ms 16232 KB
#include <bits/stdc++.h>
#include "candies.h"

using std::vector;
using std::array;
using std::pair;
using std::tuple;

using ll = long long;

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    const int n = c.size();
    const int q = v.size();
    vector<ll> sum(q + 1);
    std::map<int, pair<int, int>> map;
    map[n] = {0, 0};
    const auto get = [&](const int i, const int t) {
        const auto [s, x] = map.upper_bound(i)->second;
        return (x == 0 ? 0 : c[i]) + (sum[t] - sum[s]);
    };
    for (int i = 0; i < q; ++i) {
        assert(l[i] == 0 and r[i] == n - 1);
        sum[i + 1] = sum[i] + v[i];
        if (v[i] > 0) {
            int ok = n, ng = -1;
            while (ok - ng > 1) {
                const int md = (ok + ng) / 2;
                if (get(md, i + 1) <= c[md]) {
                    ok = md;
                } else {
                    ng = md;
                }
            }
            while (map.begin()->first < ok) {
                map.erase(map.begin());
            }
            std::cerr << ok << std::endl;
            map[ok] = {i + 1, 1};
        } else {
            int ok = n, ng = -1;
            while (ok - ng > 1) {
                const int md = (ok + ng) / 2;
                if (get(md, i + 1) >= 0) {
                    ok = md;
                } else {
                    ng = md;
                }
            }
            while (map.begin()->first < ok) {
                map.erase(map.begin());
            }
            map[ok] = {i + 1, 0};
        }
    }
    vector<int> ret(n);
    for (int i = 0; i < n; ++i) {
        ret[i] = get(i, q);
    }
    return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 99 ms 16232 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -