Submission #1368586

#TimeUsernameProblemLanguageResultExecution timeMemory
1368586ericl23302Nile (IOI24_nile)C++20
Compilation error
0 ms0 KiB
#include "nile.h"

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>

using namespace std;

typedef long long ll;
#define pl pair<ll, ll>
#define pll pair<ll, pl>
#define ppl pair<pl, pl>

vector<ppl> segTree(4e5);  // {{F'L', F'L}, {FL', FL}}
vector<ll> globalA(1), globalB(1);
ppl merge(ppl a, ppl b, ll gain) {
    if (a.first.first == 0) return b;
    if (b.first.first == 0) return a;
    ppl res = {{0, 0}, {0, 0}};
    res.first.first = min(
        min(a.first.second + b.second.first, a.first.first + b.first.first - gain), LLONG_MAX / 4);
    res.first.second =
        min(min(a.first.second + b.second.second, a.first.first + b.first.second - gain),
            LLONG_MAX / 4);
    res.second.first =
        min(min(a.second.second + b.second.first, a.second.first + b.first.first - gain),
            LLONG_MAX / 4);
    res.second.second =
        min(min(a.second.second + b.second.second, a.second.first + b.first.second - gain),
            LLONG_MAX / 4);
    return res;
}

void construct(int cur, int left, int right) {
    if (left == right) {
        segTree[cur] = {{LLONG_MAX / 4, globalA[left]}, {globalA[left], LLONG_MAX / 4}};
        return;
    }
    int mid = (left + right) / 2;
    construct(cur * 2, left, mid);
    construct(cur * 2 + 1, mid + 1, right);
    segTree[cur] = merge(segTree[cur * 2], segTree[cur * 2 + 1],
                         globalA[mid] + globalA[mid + 1] - globalB[mid] - globalB[mid + 1]);
}

ppl query(int cur, int left, int right, int qLeft, int qRight) {
    if (qRight < left || qLeft > right) return {{0, 0}, {0, 0}};
    if (qLeft <= left && qRight >= right) return segTree[cur];
    int mid = (left + right) / 2;
    return merge(query(cur * 2, left, mid, qLeft, qRight),
                 query(cur * 2 + 1, mid + 1, right, qLeft, qRight),
                 globalA[mid] + globalA[mid + 1] - globalB[mid] - globalB[mid + 1]);
}

std::vector<long long> calculate_costs(std::vector<int> W, std::vector<int> A, std::vector<int> B,
                                       std::vector<int> E) {
    int Q = E.size();
    std::vector<long long> R(Q, 0);

    int n = W.size();
    vector<pair<ll, pair<ll, ll>>> items;
    for (int i = 0; i < n; ++i) items.push_back({W[i], {A[i], B[i]}});
    sort(items.begin(), items.end());
    vector<ll> weights;
    for (auto& i : items)
        weights.push_back(i.first), globalA.push_back(i.second.first),
            globalB.push_back(i.second.second);
    // vector<pair<ll, pair<ll, ll>>> items(n);
    // for (int i = 0; i < n; ++i) items[i] = {W[i], {A[i], B[i]}};
    // sort(items.begin(), items.end());

    // vector<ll> benefit(n);
    // for (int i = 0; i < n; ++i) benefit[i] = items[i].second.first - items[i].second.second;
    map<int, int> sections;
    sections[0] = n - 1;
    vector<pl> edges;
    for (int i = 0; i < n - 1; ++i) edges.push_back({weights[i + 1] - weights[i], (ll)(i)});
    sort(edges.begin(), edges.end());

    vector<pl> queries(Q);
    for (int i = 0; i < Q; ++i) queries[i] = {E[i], i};
    sort(queries.rbegin(), queries.rend());

    construct(1, 1, n);

    auto preQ = query(1, 1, n, 1, n);
    ll curRes =
        min(min(preQ.first.first, preQ.first.second), min(preQ.second.first, preQ.second.second));
    for (auto& [d, idx] : queries) {
        while (!edges.empty()) {
            auto [len, pos] = edges.back();
            if (len <= d) break;
            edges.pop_back();
            auto section = prev(sections.upper_bound(pos));
            int left = section->first, right = section->second;
            sections.erase(section);
            sections[left] = pos;
            sections[pos + 1] = right;

            auto curQ = query(1, 1, n, left + 1, right + 1);
            curRes -= min(min(curQ.first.first, curQ.first.second),
                          min(curQ.second.first, curQ.second.second));
            curQ = query(1, 1, n, left + 1, pos + 1);
            curRes += min(min(curQ.first.first, curQ.first.second),
                          min(curQ.second.first, curQ.second.second));
            curQ = query(1, 1, n, pos + 2, right + 1);
            curRes += min(min(curQ.first.first, curQ.first.second),
                          min(curQ.second.first, curQ.second.second));
        }
        R[idx] = curRes;
    }

    return R;
}

Compilation message (stderr)

nile.cpp: In function 'std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > merge(std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> >, std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> >, ll)':
nile.cpp:23:85: error: 'LLONG_MAX' was not declared in this scope
   23 |         min(a.first.second + b.second.first, a.first.first + b.first.first - gain), LLONG_MAX / 4);
      |                                                                                     ^~~~~~~~~
nile.cpp:7:1: note: 'LLONG_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
    6 | #include <numeric>
  +++ |+#include <climits>
    7 | #include <vector>
nile.cpp: In function 'void construct(int, int, int)':
nile.cpp:38:26: error: 'LLONG_MAX' was not declared in this scope
   38 |         segTree[cur] = {{LLONG_MAX / 4, globalA[left]}, {globalA[left], LLONG_MAX / 4}};
      |                          ^~~~~~~~~
nile.cpp:38:26: note: 'LLONG_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
nile.cpp:38:87: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >, std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > >::value_type' {aka 'std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> >'} and '<brace-enclosed initializer list>')
   38 |         segTree[cur] = {{LLONG_MAX / 4, globalA[left]}, {globalA[left], LLONG_MAX / 4}};
      |                                                                                       ^
In file included from /usr/include/c++/13/bits/stl_algobase.h:64,
                 from /usr/include/c++/13/vector:62,
                 from nile.h:1,
                 from nile.cpp:1:
/usr/include/c++/13/bits/stl_pair.h:439:9: note: candidate: 'template<class _U1, class _U2> constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) requires  _S_assignable<const _U1&, const _U2&>() [with _U2 = _U1; _T1 = std::pair<long long int, long long int>; _T2 = std::pair<long long int, long long int>]'
  439 |         operator=(const pair<_U1, _U2>& __p)
      |         ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:439:9: note:   template argument deduction/substitution failed:
nile.cpp:38:87: note:   couldn't deduce template parameter '_U1'
   38 |         segTree[cur] = {{LLONG_MAX / 4, globalA[left]}, {globalA[left], LLONG_MAX / 4}};
      |                                                                                       ^
/usr/include/c++/13/bits/stl_pair.h:451:9: note: candidate: 'template<class _U1, class _U2> constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) requires  _S_assignable<_U1, _U2>() [with _U2 = _U1; _T1 = std::pair<long long int, long long int>; _T2 = std::pair<long long int, long long int>]'
  451 |         operator=(pair<_U1, _U2>&& __p)
      |         ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:451:9: note:   template argument deduction/substitution failed:
nile.cpp:38:87: note:   couldn't deduce template parameter '_U1'
   38 |         segTree[cur] = {{LLONG_MAX / 4, globalA[left]}, {globalA[left], LLONG_MAX / 4}};
      |                                                                                       ^
/usr/include/c++/13/bits/stl_pair.h:416:7: note: candidate: 'constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(const std::pair<_T1, _T2>&) requires  _S_assignable<const _T1&, const _T2&>() [with _T1 = std::pair<long long int, long long int>; _T2 = std::pair<long long int, long long int>]'
  416 |       operator=(const pair& __p)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:416:29: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> >&'
  416 |       operator=(const pair& __p)
      |                 ~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_pair.h:427:7: note: candidate: 'constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::pair<_T1, _T2>&&) requires  _S_assignable<_T1, _T2>() [with _T1 = std::pair<long long int, long long int>; _T2 = std::pair<long long int, long long int>]'
  427 |       operator=(pair&& __p)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:427:24: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> >&&'
  427 |       operator=(pair&& __p)
      |                 ~~~~~~~^~~