cpp-library

This documentation is automatically generated by competitive-verifier/competitive-verifier

View the Project on GitHub shino16/cpp-library

:warning: ds/deletable_heap.hpp

Depends on

Code

#pragma once
#include "prelude.hpp"

// Uses == for deletion
template <class T, class Comp = less<T>>
class deletable_heap: public priority_queue<T, vector<T>, Comp> {
 public:
  using priority_queue<T, vector<T>, Comp>::priority_queue;
  auto top() { return prepare(), base_t::top(); }
  void pop() { prepare(), base_t::pop(); }
  bool empty() { return prepare(), base_t::empty(); }
  // Assumes x is contained
  void del(T x) { to_del.push(move(x)); }
  auto size() const { return base_t::size() - to_del.size(); }
 private:
  using base_t = priority_queue<T, vector<T>, Comp>;
  base_t to_del;
  void prepare() {
    while (!to_del.empty() && base_t::top() == to_del.top())
      base_t::pop(), to_del.pop();
  }
};
#line 2 "prelude.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vc = vector<char>;
#define rep2(i, m, n) for (auto i = (m); i < (n); i++)
#define rep(i, n) rep2(i, 0, n)
#define repr2(i, m, n) for (auto i = (n); i-- > (m);)
#define repr(i, n) repr2(i, 0, n)
#define all(x) begin(x), end(x)
auto ndvec(int n, auto e) { return vector(n, e); }
auto ndvec(int n, auto ...e) { return vector(n, ndvec(e...)); }
auto comp_key(auto&& f) { return [&](auto&& a, auto&& b) { return f(a) < f(b); }; }
auto& max(const auto& a, const auto& b) { return a < b ? b : a; }
auto& min(const auto& a, const auto& b) { return b < a ? b : a; }
#if __cpp_lib_ranges
namespace R = std::ranges;
namespace V = std::views;
#endif
#line 3 "ds/deletable_heap.hpp"

// Uses == for deletion
template <class T, class Comp = less<T>>
class deletable_heap: public priority_queue<T, vector<T>, Comp> {
 public:
  using priority_queue<T, vector<T>, Comp>::priority_queue;
  auto top() { return prepare(), base_t::top(); }
  void pop() { prepare(), base_t::pop(); }
  bool empty() { return prepare(), base_t::empty(); }
  // Assumes x is contained
  void del(T x) { to_del.push(move(x)); }
  auto size() const { return base_t::size() - to_del.size(); }
 private:
  using base_t = priority_queue<T, vector<T>, Comp>;
  base_t to_del;
  void prepare() {
    while (!to_del.empty() && base_t::top() == to_del.top())
      base_t::pop(), to_del.pop();
  }
};
Back to top page