Language: C++

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author verytable
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <algorithm>

#include <memory>
#include <vector>


struct QueryParams {};

template<typename T, typename V, typename X>
class SegmentTreeNode {
public:
    virtual void assignLeaf(T value) = 0;

    virtual void merge(const X& left, const X& right) = 0;

    virtual V getValue() const = 0;

    virtual X query(const std::shared_ptr<QueryParams>& query_params) const {
        throw std::runtime_error("Not implemented");
    };
};

struct MaxSubarraySegmentTreeNode: public SegmentTreeNode<int, int, MaxSubarraySegmentTreeNode> {
    int max_prefix_sum, max_suffix_sum, max_sum, sum;

    void assignLeaf(int value) override {
        max_prefix_sum = max_suffix_sum = max_sum = sum = value;
    }

    void merge(const MaxSubarraySegmentTreeNode& left, const MaxSubarraySegmentTreeNode& right) override {
        sum = left.sum + right.sum;
        max_prefix_sum = std::max(left.max_prefix_sum, left.sum + right.max_prefix_sum);
        max_suffix_sum = std::max(right.max_suffix_sum, right.sum + left.max_suffix_sum);
        max_sum = std::max(max_prefix_sum,
                           std::max(max_suffix_sum,
                                    std::max(left.max_sum,
                                             std::max(right.max_sum, left.max_suffix_sum + right.max_prefix_sum))));
    }

    int getValue() const override {
        return max_sum;
    }
};

struct IntParam: public QueryParams {
    explicit IntParam(int value) : value(value) {}

    int value = 0;
};

/*
 * For searching min element in range greater or equal than given
 * */
struct BoundedMinSegmentTreeNode: public SegmentTreeNode<long long, long long, BoundedMinSegmentTreeNode> {
    static constexpr long long kMaxUpperBound = 1e16;

    std::vector<long long> elements;
    long long min;

    void assignLeaf(long long value) override {
        elements = {value};
    }

    void merge(const BoundedMinSegmentTreeNode& left, const BoundedMinSegmentTreeNode& right) override {
        std::merge(left.elements.begin(), left.elements.end(),
                   right.elements.begin(), right.elements.end(),
                   std::back_inserter(elements));
        min = std::min(left.min, right.min);
    }

    long long getValue() const override {
        return min;
    }

    BoundedMinSegmentTreeNode query(const std::shared_ptr<QueryParams> &query_params) const override {
        BoundedMinSegmentTreeNode ret;
        ret.elements = elements;
        auto upper_bound = std::static_pointer_cast<IntParam>(query_params)->value;
        auto pos = std::lower_bound(elements.begin(), elements.end(), upper_bound);
        if (pos != elements.end()) {
            ret.min = *pos;
        } else {
            ret.min = kMaxUpperBound;
        }
        return ret;
    }
};

/*
 * For searching max element in range less or equal than given
 * */
struct BoundedMaxSegmentTreeNode: public SegmentTreeNode<int, int, BoundedMaxSegmentTreeNode> {
    static constexpr int kMinLowerBound = -1e9;

    std::vector<int> elements;
    int max;

    void assignLeaf(int value) override {
        elements = {value};
    }

    void merge(const BoundedMaxSegmentTreeNode& left, const BoundedMaxSegmentTreeNode& right) override {
        std::merge(left.elements.begin(), left.elements.end(),
                   right.elements.begin(), right.elements.end(),
                   std::back_inserter(elements));
        max = std::max(left.max, right.max);
    }

    int getValue() const override {
        return max;
    }

    BoundedMaxSegmentTreeNode query(const std::shared_ptr<QueryParams> &query_params) const override {
        BoundedMaxSegmentTreeNode ret;
        ret.elements = elements;
        auto lower_bound = std::static_pointer_cast<IntParam>(query_params)->value;
        auto pos = std::lower_bound(elements.begin(), elements.end(), lower_bound);
        if (pos != elements.end()) {
            if (*pos == lower_bound) {
                ret.max = lower_bound;
            } else {
                if (pos == elements.begin()) {
                    ret.max = kMinLowerBound;
                } else {
                    ret.max = *std::prev(pos);
                }
            }
        } else {
            ret.max = elements.back();
        }
        return ret;
    }
};

// T is the type of input array elements
// V is the type of required aggregate statistic
// Node must implement SegmentTreeNode
template<typename T, typename V, typename Node>
class SegmentTree {
public:
    explicit SegmentTree(const std::vector<T> &arr) : array_size_(arr.size()) {
        nodes_.resize(getSegmentTreeSize());
        buildTree(arr, 1, 0, array_size_ - 1);
    }

    V getValue(size_t lo, size_t hi, const std::shared_ptr<QueryParams> &query_params = nullptr) const {
        auto result = getValue(1, 0, array_size_ - 1, lo, hi, query_params);
        return result.getValue();
    }

private:
    std::vector<Node> nodes_{};
    size_t array_size_;

    void buildTree(const std::vector<T> &arr, size_t stIndex, size_t lo, size_t hi) {
        if (lo == hi) {
            nodes_[stIndex].assignLeaf(arr[lo]);
            return;
        }

        size_t left = 2 * stIndex;
        size_t right = left + 1;
        size_t mid = (lo + hi) / 2;

        buildTree(arr, left, lo, mid);
        buildTree(arr, right, mid + 1, hi);
        nodes_[stIndex].merge(nodes_[left], nodes_[right]);
    }

    Node getValue(size_t st_index, size_t left, size_t right, size_t lo, size_t hi,
                  const std::shared_ptr<QueryParams> &query_params = nullptr) const {  // todo make type alias
        if (left == lo && right == hi) {
            if (query_params) {
                return nodes_[st_index].query(query_params);
            } else {
                return nodes_[st_index];
            }
        }

        size_t mid = (left + right) / 2;

        if (lo > mid) {
            return getValue(2 * st_index + 1, mid + 1, right, lo, hi, query_params);
        }

        if (hi <= mid) {
            return getValue(2 * st_index, left, mid, lo, hi, query_params);
        }

        auto left_result = getValue(2 * st_index, left, mid, lo, mid, query_params);
        auto right_result = getValue(2 * st_index + 1, mid + 1, right, mid + 1, hi, query_params);

        Node result;
        result.merge(left_result, right_result);

        return result;
    }

    size_t getSegmentTreeSize() {
        size_t size = 1;
        for (; size < array_size_; size <<= 1);
        return size << 1;
    }

    void update(size_t st_index, size_t lo, size_t hi, size_t index, T value) {
        if (lo == hi) {
            nodes_[st_index].assignLeaf(value);
            return;
        }

        size_t left = 2 * st_index;
        size_t right = left + 1;
        size_t mid = (lo + hi) / 2;

        if (index <= mid) {
            update(left, lo, mid, index, value);
        } else {
            update(right, mid + 1, hi, index, value);
        }

        nodes_[st_index].merge(nodes_[left], nodes_[right]);
    }
};


struct Query {

    long long t;
    long long a;
};

struct IndexedBound {
    IndexedBound(long long int bound, long long int index) : bound(bound), index(index) {}

    long long bound;
    long long index;

};


class TaskF {
public:
    void solve(std::istream &in, std::ostream &out) {
        size_t X, K;
        in >> X >> K;
        std::vector<long long> rs;
        rs.reserve(K);
        for (int i = 0; i < K; ++i) {
            int r;
            in >> r;
            rs.push_back(r);
        }

        size_t Q;
        in >> Q;
        std::vector<Query> qs;
        qs.reserve(Q);
        for (int i = 0; i < Q; ++i) {
            long long t, a;
            in >> t >> a;
            qs.emplace_back(t, a);
        }

        std::vector<IndexedBound> upper_bounds;
        upper_bounds.reserve(K / 2);
        std::vector<IndexedBound> lower_bounds;
        lower_bounds.reserve(K / 2);

        long long S = X;
        long long P = X - std::max(0ull, X - rs[0]);
        for (int i = 0; i < K; ++i) {
            bool is_even = i % 2 == 0;
            if (i == 0) {
                upper_bounds.emplace_back(std::min(rs[0], (long long) X), 1);
            } else if (is_even) {
                if (rs[i] - rs[i - 1] >= X) {
                    upper_bounds.emplace_back(X, i + 1);
                } else {
                    if (S - (rs[i] - rs[i - 1]) <= 0) {
                        long long to_add = (rs[i] - rs[i - 1]) - S;
                        upper_bounds.emplace_back(std::min((long long) X, rs[0] + to_add), i + 1);
                    }
                }
            } else {
                if (rs[i] - rs[i - 1] >= X) {
                    lower_bounds.emplace_back(0, i + 1);
                } else {
                    if (P - (rs[i] - rs[i - 1]) <= 0) {
                        long long to_sub = (rs[i] - rs[i - 1]) - P;
                        lower_bounds.emplace_back(std::max(0ull, X - to_sub), i + 1);
                    }
                }
            }
            if (i > 0) {
                S = X - std::max(0ll, S - (rs[i] - rs[i - 1]));
                P = X - std::max(0ll, P - (rs[i] - rs[i - 1]));
            }
        }

        std::sort(upper_bounds.begin(), upper_bounds.end());
        std::sort(lower_bounds.begin(), lower_bounds.end());

        std::vector<int> sorted_upper_bound_indices;
        sorted_upper_bound_indices.reserve(upper_bounds.size());
        for (const auto &item: upper_bounds) {
            sorted_upper_bound_indices.push_back(item.index);
        }

        std::vector<int> sorted_lower_bound_indices;
        sorted_lower_bound_indices.reserve(lower_bounds.size());
        for (const auto &item: lower_bounds) {
            sorted_lower_bound_indices.push_back(item.index);
        }

        //std::cout << "upper bounds:\n";
        for (const auto &b: upper_bounds) {
            //std::cout << "bound: " << b.bound << " index: " << b.index << "\n";
        }
        //std::cout << "\n";

        //std::cout << "lower bounds:\n";
        for (const auto &b: lower_bounds) {
            //std::cout << "bound: " << b.bound << " index: " << b.index << "\n";
        }
        //std::cout << "\n";

        //std::cout << "upper bound indices:\n";
        for (auto i: sorted_upper_bound_indices) {
            //std::cout << i << " ";
        }
        //std::cout << "\n";

        //std::cout << "lower bound indices:\n";
        for (auto i: sorted_lower_bound_indices) {
            //std::cout << i << " ";
        }
        //std::cout << "\n";

        std::vector<long long> zero_start_sums;
        zero_start_sums.reserve(K);
        S = 0;
        zero_start_sums.push_back(S);
        for (int i = 0; i < K; ++i) {
            bool is_even = i % 2 == 0;
            if (is_even) {
                S -= rs[i];
                if (i > 0) {
                    S += rs[i - 1];
                }
                zero_start_sums.push_back(S);
            } else {
                S += rs[i] - rs[i - 1];
                zero_start_sums.push_back(S);
            }
        }

        //std::cout << "Zero start sums:\n";
        for (long long zero_start_sum : zero_start_sums) {
            //std::cout << zero_start_sum << " ";
        }
        //std::cout << "\n";

        std::unique_ptr<SegmentTree<int, int, BoundedMaxSegmentTreeNode>> upper_bounds_tree = nullptr;
        if (!sorted_upper_bound_indices.empty()) {
            upper_bounds_tree.reset(new SegmentTree<int, int, BoundedMaxSegmentTreeNode>(sorted_upper_bound_indices));
        }
        //std::cout << "upper tree built\n";

        std::unique_ptr<SegmentTree<int, int, BoundedMaxSegmentTreeNode>> lower_bounds_tree = nullptr;
        if (!sorted_lower_bound_indices.empty()) {
            lower_bounds_tree.reset(new SegmentTree<int, int, BoundedMaxSegmentTreeNode>(sorted_lower_bound_indices));
        }
        //std::cout << "lower tree built\n";

        //std::cout << "queries:\n";
        for (const auto &q: qs) {
            //std::cout << "query: a = " << q.a << " t = " << q.t << "\n";

            auto upper_bound = find_upper_bound(upper_bounds, q.a);
            //std::cout << "upper bound index = " << upper_bound << "\n";

            auto lower_bound = find_lower_bound(lower_bounds, q.a);
            //std::cout << "lower bound index = " << lower_bound << "\n";

            auto max_rs_index = find_rs_index(rs, q.t);
            //std::cout << "max rs index is " << max_rs_index << "\n";

            long long start = 0;
            if (max_rs_index != -1) {
                int max_upper_zeroing = -1;
                if (upper_bound != -1) {
                    auto query_params = std::make_shared<IntParam>(max_rs_index + 1);
                    auto res = upper_bounds_tree->getValue(upper_bound, sorted_upper_bound_indices.size() - 1,
                                                           query_params);
                    max_upper_zeroing = std::max(res, max_upper_zeroing);
                }
                int max_lower_zeroing = -1;
                if (lower_bound != -1) {
                    auto query_params = std::make_shared<IntParam>(max_rs_index + 1);
                    auto res = lower_bounds_tree->getValue(0, lower_bound, query_params);
                    max_lower_zeroing = std::max(res, max_lower_zeroing);
                }

                //std::cout << "max upper zeroing is " << max_upper_zeroing << "\n";
                //std::cout << "max lower zeroing is " << max_lower_zeroing << "\n";

                int max_zeroing = std::max(max_upper_zeroing, max_lower_zeroing);
                if (max_zeroing > 0) {
                    start = max_zeroing;
                }
            }

            //std::cout << "start: " << start << "\n";

            long long answer = 0;
            if (start == 0) {
                if (q.t == 0) {
                    answer = q.a;
                } else {
                    bool is_down = max_rs_index < 0 || (max_rs_index % 2 == 1);
                    //std::cout << "is down = " << is_down << "\n";
                    int index = max_rs_index < 0 ? 0 : max_rs_index + 1;
                    answer = q.a + zero_start_sums[index];
                    if (is_down) {
                        answer -= q.t;
                        if (max_rs_index >= 0) {
                            answer += rs[max_rs_index];
                        }
                        if (answer < 0) {
                            answer = 0;
                        }
                    } else {
                        answer += q.t;
                        if (max_rs_index >= 0) {
                            answer -= rs[max_rs_index];
                        }
                        if (answer < 0) {
                            answer = 0;
                        }
                        answer = X - answer;
                    }
                }
            } else {
                if (q.t == rs[start - 1]) {
                    answer = X;
                } else {
                    bool is_down = (max_rs_index + 1 - start) % 2 == 0;
                    //std::cout << "is down: " << is_down << "\n";
                    if (is_down) {
                        if (max_rs_index % 2 == 1) {
                            answer = zero_start_sums[max_rs_index + 1];
                            answer -= zero_start_sums[start];
                            answer += X;
                            answer -= q.t;
                            answer += rs[max_rs_index];
                        } else {
                            answer = -zero_start_sums[max_rs_index + 1];
                            answer += zero_start_sums[start];
                            answer += X;
                            answer -= q.t;
                            answer += rs[max_rs_index];
                        }
                        if (answer < 0) {
                            answer = 0;
                        }
                    } else {
                        if (max_rs_index % 2 == 1) {
                            answer = -zero_start_sums[max_rs_index + 1];
                            answer += zero_start_sums[start];
                            answer += X;
                            answer += q.t;
                            answer -= rs[max_rs_index];
                        } else {
                            answer = zero_start_sums[max_rs_index + 1];
                            answer -= zero_start_sums[start];
                            answer += X;
                            answer += q.t;
                            answer -= rs[max_rs_index];
                            //std::cout << zero_start_sums[max_rs_index + 1] << " " << -zero_start_sums[start] << " " << X << " " << q.t << " " << -rs[max_rs_index] << "\n";
                        }
                        if (answer < 0) {
                            answer = 0;
                        }
                        answer = X - answer;
                    }
                }
            }

            if (max_rs_index >= 0 && max_rs_index % 2 == 0) {
                answer = X - answer;
            }

//            std::cout << "answer is " << answer << "\n";

            out << answer << "\n";

            //std::cout << "\n";
        }
    }

    int find_rs_index(const std::vector<long long> &rs, long long t) {
        auto upper_bound = t;
        auto pos = std::upper_bound(rs.begin(), rs.end(), upper_bound);
        if (pos != rs.end()) {
            if (pos == rs.begin()) {
                return -1;
            } else {
                return (pos - rs.begin()) - 1;
            }
        } else {
            return rs.size() - 1;
        }
    }

    int find_upper_bound(const std::vector<IndexedBound> &upper_bounds, long long a) {
        auto upper_bound = IndexedBound(a - 1, kMaxIndex);
        auto pos = std::upper_bound(upper_bounds.begin(), upper_bounds.end(), upper_bound);
        if (pos != upper_bounds.end()) {
            return pos - upper_bounds.begin();
        } else {
            return -1;
        }
    }

    int find_lower_bound(const std::vector<IndexedBound> &lower_bounds, long long a) {
        auto lower_bound = IndexedBound(a, kMaxIndex);
        auto pos = std::upper_bound(lower_bounds.begin(), lower_bounds.end(), lower_bound);
        if (pos != lower_bounds.end()) {
            if (pos == lower_bounds.begin()) {
                return -1;
            } else {
                return (pos - lower_bounds.begin()) - 1;
            }
        } else {
            return lower_bounds.size() - 1;
        }
    }

private:
    static constexpr int kMaxIndex = 2 * 1e9;

};


int main() {
    TaskF solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Compiler output:
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
                 from /usr/include/c++/14/bits/allocator.h:46,
                 from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:7:
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = Query; _Args = {long long int&, long long int&}; _Tp = Query]':
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = Query; _Args = {long long int&, long long int&}; _Tp = Query; allocator_type = std::allocator<Query>]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:117:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {long long int&, long long int&}; _Tp = Query; _Alloc = std::allocator<Query>; reference = Query&]'
  117 |             _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118 |                                      std::forward<_Args>(__args)...);
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:271:28:   required from here
  271 |             qs.emplace_back(t, a);
      |             ~~~~~~~~~~~~~~~^~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: new initializer expression list treated as compound expression [-fpermissive]
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: no matching function for call to 'Query::Query(long long int&)'
a.cc:236:8: note: candidate: 'Query::Query()'
  236 | struct Query {
      |        ^~~~~
a.cc:236:8: note:   candidate expects 0 arguments, 1 provided
a.cc:236:8: note: candidate: 'constexpr Query::Query(const Query&)'
a.cc:236:8: note:   no known conversion for argument 1 from 'long long int' to 'const Query&'
a.cc:236:8: note: candidate: 'constexpr Query::Query(Query&&)'
a.cc:236:8: note:   no known conversion for argument 1 from 'long long int' to 'Query&&'
In file included from /usr/include/c++/14/bits/stl_algobase.h:71,
                 from /usr/include/c++/14/string:51:
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_less_iter::operator()(_Value&, _Iterator) const [with _Value = const IndexedBound; _Iterator = __gnu_cxx::__normal_iterator<const IndexedBound*, std::vector<IndexedBound> >]':
/usr/include/c++/14/bits/stl_algo.h:1993:14:   required from '_ForwardIterator std::__upper_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = __gnu_cxx::__normal_iterator<const IndexedBound*, vector<IndexedBound> >; _Tp = IndexedBound; _Compare = __gnu_cxx::__ops::_Val_less_iter]'
 1993 |           if (__comp(__val, __middle))
      |               ~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:2028:32:   required from '_FIter std::upper_bound(_FIter, _FIter, const _Tp&) [with _FIter = __gnu_cxx::__normal_iterator<const IndexedBound*, vector<IndexedBound> >; _Tp = IndexedBound]'
 2028 |       return std::__upper_bound(__first, __last, __val,
      |              ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
 2029 |                                 __gnu_cxx::__ops::__val_less_iter());
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:527:36:   required from here
  527 |         auto pos = std::upper_bound(upper_bounds.begin(), upper_bounds.end(), upper_bound);
      |                    ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:98:22: error: no match for 'operator<' (operand types are 'const IndexedBound' and 'const IndexedBound')
   98 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/14/string:48:
/usr/include/c++/14/bits/stl_iterator.h:1241:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)'
 1241 |     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1241:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:98:22: note:   'const IndexedBound' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>'
   98 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1249:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&)'
 1249 |     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1249:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:98:22: note:   'const IndexedBound' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>'
   98 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = __gnu_cxx::__normal_iterator<IndexedBound*, std::vector<IndexedBound> >; _Iterator2 = __gnu_cxx::__normal_iterator<IndexedBound*, std::vector<IndexedBound> >]':
/usr/include/c++/14/bits/stl_algo.h:1777:14:   required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<IndexedBound*, vector<IndexedBound> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
 1777 |           if (__comp(__i, __first))
      |               ~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1817:25:   required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<IndexedBound*, vector<IndexedBound> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
 1817 |           std::__insertion_sort(__first, __first + int(_S_threshold), __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1908:31:   required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<IndexedBound*, vector<IndexedBound> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]'
 1908 |           std::__final_insertion_sort(__first, __last, __comp);
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4772:18:   required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<IndexedBound*, vector<IndexedBound> >]'
 4772 |       std::__sort(__first, __last, __gnu_cxx::__ops::__iter_less_iter());
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:310:18:   required from here
  310 |         std::sort(upper_bounds.begin(), upper_bounds.end());
      |         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h:45:23: error: no match for 'operator<' (operand types are 'IndexedBound' and 'IndexedBound')
   45 |       { return *__it1 < *__it2; }
      |                ~~~~~~~^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1241:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)'
 1241 |     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1241:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:45:23: note:   'IndexedBound' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>'
   45 |       { return *__it1 < *__it2; }
      |                ~~~~~~~^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1249:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&)'
 1249 |     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1249:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/predefined_ops.h:45:23: note:   'IndexedBound' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>'
   45 |       { return *__it1 < *__it2; }
      |                ~~~~~~~^~~~~~~~
/usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_less_iter::operator()(_Value&, _Iterator) const [with _Value = IndexedBound; _Iterator = __gnu_cxx::__normal_iterator<IndexedBound*, std::vector<IndexedBound> >]':
/usr/include/c++/14/bits/stl_algo.h:1757:20:   required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<IndexedBound*, vector<IndexedBound> >; _Compare = __gnu_cxx::__ops::_Val_less_iter]'
 1757 |       while (__comp(__val, __next))
      |              ~~~~~~^~~~~~~~~~~~~~~
/usr/include/c++/1