#include #include #include #include #include #include #include namespace nono { template struct EdgeBase { int from; int to; T weight; EdgeBase() {} EdgeBase(int from, int to, T weight = 1): from(from), to(to), weight(weight) {} }; using Edge = EdgeBase; template using WeightedEdge = EdgeBase; template class Graph { struct Edge_ { int to; T weight; int id; }; using iterator = std::vector::iterator; using const_iterator = std::vector::const_iterator; using subrange = std::ranges::subrange; using const_subrange = std::ranges::subrange; public: template friend Graph to_undirected_graph(int n, const std::vector>& edges); template friend Graph to_directed_graph(int n, const std::vector>& edges); subrange operator[](int i) { return std::ranges::subrange(edges_.begin() + indptr_[i], edges_.begin() + indptr_[i + 1]); } const_subrange operator[](int i) const { return std::ranges::subrange(edges_.begin() + indptr_[i], edges_.begin() + indptr_[i + 1]); } int size() const { return n_; } bool is_directed() const { return directed_; } bool is_undirected() const { return !is_directed(); } private: Graph(int n, const std::vector>& edges, bool directed) : n_(n), indptr_(n + 1), edges_(directed ? edges.size() : 2 * edges.size()), directed_(directed) { for (const auto& edge: edges) { indptr_[edge.from + 1]++; if (!directed) indptr_[edge.to + 1]++; } for (int i = 0; i < n_; i++) { indptr_[i + 1] += indptr_[i]; } auto index = indptr_; for (int i = 0; i < std::ssize(edges); i++) { const auto& edge = edges[i]; edges_[index[edge.from]++] = Edge_(edge.to, edge.weight, i); if (!directed) edges_[index[edge.to]++] = Edge_(edge.from, edge.weight, i); } } int n_; std::vector indptr_; std::vector edges_; bool directed_; }; template Graph to_undirected_graph(int n, const std::vector>& edges) { return Graph(n, edges, false); } template Graph to_directed_graph(int n, const std::vector>& edges) { return Graph(n, edges, true); } } // namespace nono namespace nono { template struct SegmentEdge { std::pair from; std::pair to; T weight; }; template std::pair, std::vector> to_graph(int n, const std::vector>& seg_edges) { int m = seg_edges.size(); std::vector> edges; auto from = [n](int id) { return (n <= id ? id : id + 2 * n); }; auto to = [](int id) { return id; }; for (int u = n - 1; u > 0; u--) { edges.emplace_back(to(u), to(2 * u), 0); edges.emplace_back(to(u), to(2 * u + 1), 0); } for (int u = n - 1; u > 0; u--) { edges.emplace_back(from(2 * u), from(u), 0); edges.emplace_back(from(2 * u + 1), from(u), 0); } for (int i = 0; i < m; i++) { int edge_id = i + 3 * n; { auto [left, right] = seg_edges[i].from; for (left += n, right += n; left < right; left >>= 1, right >>= 1) { if (left & 1) { edges.emplace_back(from(left++), edge_id, 0); } if (right & 1) { edges.emplace_back(from(--right), edge_id, 0); } } } { auto [left, right] = seg_edges[i].to; for (left += n, right += n; left < right; left >>= 1, right >>= 1) { if (left & 1) { edges.emplace_back(edge_id, to(left++), seg_edges[i].weight); } if (right & 1) { edges.emplace_back(edge_id, to(--right), seg_edges[i].weight); } } } } std::vector mapping(3 * n + m, -1); for (int i = 0; i < n; i++) { mapping[i + n] = i; } return {to_directed_graph(3 * n + m, edges), mapping}; } } // namespace nono #include #include #include namespace nono { template class Compressor { public: Compressor() = default; Compressor(const std::vector& data): data_(data) { std::sort(data_.begin(), data_.end()); data_.erase(std::unique(data_.begin(), data_.end()), data_.end()); } Compressor(std::vector&& data): data_(data) { std::sort(data_.begin(), data_.end()); data_.erase(std::unique(data_.begin(), data_.end()), data_.end()); } int compress(const T& value) const { return std::distance(data_.begin(), std::lower_bound(data_.begin(), data_.end(), value)); } std::vector compress(const std::vector& vec) const { std::vector result(vec.size()); for (int i = 0; auto v: vec) { result[i] = compress(v); i++; } return result; } T decompress(int i) const { return data_[i]; } int size() const { return data_.size(); } bool contains(const T& value) const { auto it = std::ranges::lower_bound(data_, value); return it != data_.end() && *it == value; } private: std::vector data_; }; } // namespace nono #include #include namespace nono { template std::vector> strongly_connected_components(const Graph& graph) { constexpr int NONE = -1; int n = graph.size(); std::vector order(n, NONE); std::vector group_ids(n, NONE); std::vector count(n); std::vector history; history.reserve(n); int now = 0; int group_id = 0; auto dfs = [&](const auto& self, int u) -> int { int lowlink = order[u] = now++; history.push_back(u); for (const auto& edge: graph[u]) { if (order[edge.to] == NONE) { lowlink = std::min(lowlink, self(self, edge.to)); } else if (group_ids[edge.to] == NONE) { lowlink = std::min(lowlink, order[edge.to]); } } if (lowlink == order[u]) { while (!history.empty()) { int v = history.back(); if (order[v] < order[u]) break; history.pop_back(); group_ids[v] = group_id; count[group_id]++; } group_id++; } return lowlink; }; for (int i = 0; i < n; i++) { if (order[i] == NONE) { dfs(dfs, i); } } std::vector> groups(group_id); for (int i = 0; i < group_id; i++) { groups[group_id - i - 1].reserve(count[i]); } for (int i = 0; i < n; i++) { groups[group_id - group_ids[i] - 1].push_back(i); } return groups; } } // namespace nono namespace nono { void solve() { int n, a, b; std::cin >> n >> a >> b; std::vector x(n); for (int i = 0; i < n; i++) std::cin >> x[i]; Compressor compressor(x); std::vector> edges; for (int i = 0; i < n; i++) { { int left = compressor.compress(x[i] + a); int right = compressor.compress(x[i] + b + 1); edges.emplace_back(std::pair(i, i + 1), std::pair(left, right), 1); } { int left = compressor.compress(x[i] - b); int right = compressor.compress(x[i] - a + 1); edges.emplace_back(std::pair(i, i + 1), std::pair(left, right), 1); } } auto [graph, mapping] = to_graph(n, edges); std::vector ans(n); for (auto&& group: strongly_connected_components(graph)) { int count = 0; for (auto u: group) { if (mapping[u] != -1) count++; } for (auto u: group) { if (mapping[u] != -1) ans[mapping[u]] = count; } } for (int i = 0; i < n; i++) { std::cout << ans[i] << '\n'; } } } // namespace nono int main() { std::cin.tie(0)->sync_with_stdio(0); nono::solve(); }