This documentation is automatically generated by competitive-verifier/competitive-verifier
// competitive-verifier: PROBLEM https://yukicoder.me/problems/no/1170
// competitive-verifier: TLE 0.5
// competitive-verifier: MLE 256
#include <iostream>
#include <algorithm>
#include "src/Graph/RangeToRangeGraph.hpp"
#include "src/Graph/StronglyConnectedComponents.hpp"
using namespace std;
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
int N, A, B;
cin >> N >> A >> B;
int x[N];
for (int i= 0; i < N; ++i) cin >> x[i];
RangeToRangeGraph r2r(N);
for (int i= 0; i < N; ++i) {
int l= lower_bound(x, x + N, x[i] + A) - x;
int r= upper_bound(x, x + N, x[i] + B) - x;
r2r.add_to_range(i, l, r), r2r.add_from_range(l, r, i);
}
// 無向グラフだと思うと全部くっついちゃうので 例えばUFとかは使えない
StronglyConnectedComponents scc(r2r.graph);
int C= scc.size();
int cnt[C];
fill_n(cnt, C, 0);
for (int i= 0; i < N; ++i) ++cnt[scc(i)];
for (int i= 0; i < N; ++i) cout << cnt[scc(i)] << '\n';
return 0;
}
#line 1 "test/yukicoder/1170.test.cpp"
// competitive-verifier: PROBLEM https://yukicoder.me/problems/no/1170
// competitive-verifier: TLE 0.5
// competitive-verifier: MLE 256
#include <iostream>
#include <algorithm>
#line 2 "src/Internal/ListRange.hpp"
#include <vector>
#line 4 "src/Internal/ListRange.hpp"
#include <iterator>
#include <type_traits>
#define _LR(name, IT, CT) \
template <class T> struct name { \
using Iterator= typename std::vector<T>::IT; \
Iterator bg, ed; \
Iterator begin() const { return bg; } \
Iterator end() const { return ed; } \
size_t size() const { return std::distance(bg, ed); } \
CT &operator[](int i) const { return bg[i]; } \
}
_LR(ListRange, iterator, T);
_LR(ConstListRange, const_iterator, const T);
#undef _LR
template <class T> struct CSRArray {
std::vector<T> dat;
std::vector<int> p;
size_t size() const { return p.size() - 1; }
ListRange<T> operator[](int i) { return {dat.begin() + p[i], dat.begin() + p[i + 1]}; }
ConstListRange<T> operator[](int i) const { return {dat.cbegin() + p[i], dat.cbegin() + p[i + 1]}; }
};
template <template <class> class F, class T> std::enable_if_t<std::disjunction_v<std::is_same<F<T>, ListRange<T>>, std::is_same<F<T>, ConstListRange<T>>, std::is_same<F<T>, CSRArray<T>>>, std::ostream &> operator<<(std::ostream &os, const F<T> &r) {
os << '[';
for (int _= 0, __= r.size(); _ < __; ++_) os << (_ ? ", " : "") << r[_];
return os << ']';
}
#line 3 "src/Graph/Graph.hpp"
struct Edge: std::pair<int, int> {
using std::pair<int, int>::pair;
Edge &operator--() { return --first, --second, *this; }
int to(int v) const { return first ^ second ^ v; }
friend std::istream &operator>>(std::istream &is, Edge &e) { return is >> e.first >> e.second, is; }
};
struct Graph: std::vector<Edge> {
size_t n;
Graph(size_t n= 0, size_t m= 0): vector(m), n(n) {}
size_t vertex_size() const { return n; }
size_t edge_size() const { return size(); }
size_t add_vertex() { return n++; }
size_t add_edge(int s, int d) { return emplace_back(s, d), size() - 1; }
size_t add_edge(Edge e) { return emplace_back(e), size() - 1; }
#define _ADJ_FOR(a, b) \
for (auto [u, v]: *this) a; \
for (size_t i= 0; i < n; ++i) p[i + 1]+= p[i]; \
for (int i= size(); i--;) { \
auto [u, v]= (*this)[i]; \
b; \
}
#define _ADJ(a, b) \
vector<int> p(n + 1), c(size() << !dir); \
if (!dir) { \
_ADJ_FOR((++p[u], ++p[v]), (c[--p[u]]= a, c[--p[v]]= b)) \
} else if (dir > 0) { \
_ADJ_FOR(++p[u], c[--p[u]]= a) \
} else { \
_ADJ_FOR(++p[v], c[--p[v]]= b) \
} \
return {c, p}
CSRArray<int> adjacency_vertex(int dir) const { _ADJ(v, u); }
CSRArray<int> adjacency_edge(int dir) const { _ADJ(i, i); }
#undef _ADJ
#undef _ADJ_FOR
};
#line 3 "src/Graph/RangeToRangeGraph.hpp"
template <typename cost_t= int> class RangeToRangeGraph {
int n;
inline int to_upper_idx(int i) const { return i >= n ? i - n : n + i; }
inline int to_lower_idx(int i) const { return i >= n ? i - n : n + n + i; }
public:
Graph graph;
std::vector<cost_t> weight;
RangeToRangeGraph(int n): n(n), graph(n * 3) {
for (int i= 2; i < n + n; ++i) add(to_upper_idx(i / 2), to_upper_idx(i));
for (int i= 2; i < n + n; ++i) add(to_lower_idx(i), to_lower_idx(i / 2));
}
void add(int s, int t, cost_t w= 0) { graph.add_edge(s, t), weight.emplace_back(w); }
// [s_l, s_r) -> t
void add_from_range(int s_l, int s_r, int t, cost_t w= 0) {
for (int l= s_l + n, r= s_r + n; l < r; l>>= 1, r>>= 1) {
if (l & 1) add(to_lower_idx(l++), t, w);
if (r & 1) add(to_lower_idx(--r), t, w);
}
}
// s -> [t_l, t_r)
void add_to_range(int s, int t_l, int t_r, cost_t w= 0) {
for (int l= t_l + n, r= t_r + n; l < r; l>>= 1, r>>= 1) {
if (l & 1) add(s, to_upper_idx(l++), w);
if (r & 1) add(s, to_upper_idx(--r), w);
}
}
// [s_l, s_r) -> [t_l, t_r)
void add_from_range_to_range(int s_l, int s_r, int t_l, int t_r, cost_t w= 0) { add_from_range(s_l, s_r, graph.n, w), add_to_range(graph.n, t_l, t_r, 0), ++graph.n; }
};
#line 4 "src/Graph/StronglyConnectedComponents.hpp"
class StronglyConnectedComponents {
std::vector<int> m, q, b;
public:
StronglyConnectedComponents(const Graph &g) {
const int n= g.vertex_size();
m.assign(n, -2), b.resize(n);
{
auto adj= g.adjacency_vertex(1);
std::vector<int> c(adj.p.begin(), adj.p.begin() + n);
for (int s= 0, k= n, p; s < n; ++s)
if (m[s] == -2)
for (m[p= s]= -1; p >= 0;) {
if (c[p] == adj.p[p + 1]) b[--k]= p, p= m[p];
else if (int w= adj.dat[c[p]++]; m[w] == -2) m[w]= p, p= w;
}
}
auto adj= g.adjacency_vertex(-1);
std::vector<char> z(n);
int k= 0, p= 0;
q= {0};
for (int s: b)
if (!z[s]) {
for (z[m[k++]= s]= 1; p < k; ++p)
for (int u: adj[m[p]])
if (!z[u]) z[m[k++]= u]= 1;
q.push_back(k);
}
for (int i= q.size() - 1; i--;)
while (k > q[i]) b[m[--k]]= i;
}
size_t size() const { return q.size() - 1; }
ConstListRange<int> block(int k) const { return {m.cbegin() + q[k], m.cbegin() + q[k + 1]}; }
int operator()(int i) const { return b[i]; }
Graph dag(const Graph &g) const {
Graph ret(size());
for (auto [s, d]: g)
if (b[s] != b[d]) ret.add_edge(b[s], b[d]);
return std::sort(ret.begin(), ret.end()), ret.erase(std::unique(ret.begin(), ret.end()), ret.end()), ret;
}
};
#line 8 "test/yukicoder/1170.test.cpp"
using namespace std;
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
int N, A, B;
cin >> N >> A >> B;
int x[N];
for (int i= 0; i < N; ++i) cin >> x[i];
RangeToRangeGraph r2r(N);
for (int i= 0; i < N; ++i) {
int l= lower_bound(x, x + N, x[i] + A) - x;
int r= upper_bound(x, x + N, x[i] + B) - x;
r2r.add_to_range(i, l, r), r2r.add_from_range(l, r, i);
}
// 無向グラフだと思うと全部くっついちゃうので 例えばUFとかは使えない
StronglyConnectedComponents scc(r2r.graph);
int C= scc.size();
int cnt[C];
fill_n(cnt, C, 0);
for (int i= 0; i < N; ++i) ++cnt[scc(i)];
for (int i= 0; i < N; ++i) cout << cnt[scc(i)] << '\n';
return 0;
}
Env | Name | Status | Elapsed | Memory |
---|---|---|---|---|
g++-13 | 0_sample_0.txt |
![]() |
7 ms | 4 MB |
g++-13 | 0_sample_1.txt |
![]() |
6 ms | 4 MB |
g++-13 | 1_small_0_0.txt |
![]() |
6 ms | 4 MB |
g++-13 | 1_small_0_1.txt |
![]() |
6 ms | 4 MB |
g++-13 | 1_small_0_2.txt |
![]() |
6 ms | 4 MB |
g++-13 | 1_small_0_3.txt |
![]() |
6 ms | 4 MB |
g++-13 | 1_small_0_4.txt |
![]() |
6 ms | 4 MB |
g++-13 | 1_small_0_5.txt |
![]() |
6 ms | 4 MB |
g++-13 | 1_small_0_6.txt |
![]() |
6 ms | 4 MB |
g++-13 | 1_small_0_7.txt |
![]() |
6 ms | 4 MB |
g++-13 | 1_small_0_8.txt |
![]() |
6 ms | 4 MB |
g++-13 | 1_small_0_9.txt |
![]() |
6 ms | 4 MB |
g++-13 | 2_medium_0_0.txt |
![]() |
6 ms | 4 MB |
g++-13 | 2_medium_0_1.txt |
![]() |
6 ms | 4 MB |
g++-13 | 2_medium_0_2.txt |
![]() |
6 ms | 4 MB |
g++-13 | 2_medium_0_3.txt |
![]() |
6 ms | 4 MB |
g++-13 | 2_medium_0_4.txt |
![]() |
6 ms | 4 MB |
g++-13 | 2_medium_0_5.txt |
![]() |
6 ms | 4 MB |
g++-13 | 2_medium_0_6.txt |
![]() |
6 ms | 4 MB |
g++-13 | 2_medium_0_7.txt |
![]() |
6 ms | 4 MB |
g++-13 | 2_medium_0_8.txt |
![]() |
6 ms | 4 MB |
g++-13 | 2_medium_0_9.txt |
![]() |
6 ms | 4 MB |
g++-13 | 2_medium_1_0.txt |
![]() |
7 ms | 4 MB |
g++-13 | 2_medium_1_1.txt |
![]() |
7 ms | 4 MB |
g++-13 | 2_medium_1_2.txt |
![]() |
7 ms | 4 MB |
g++-13 | 2_medium_1_3.txt |
![]() |
7 ms | 4 MB |
g++-13 | 2_medium_1_4.txt |
![]() |
6 ms | 4 MB |
g++-13 | 3_large_0_0.txt |
![]() |
94 ms | 48 MB |
g++-13 | 3_large_0_1.txt |
![]() |
101 ms | 49 MB |
g++-13 | 3_large_0_2.txt |
![]() |
95 ms | 47 MB |
g++-13 | 3_large_0_3.txt |
![]() |
98 ms | 50 MB |
g++-13 | 3_large_0_4.txt |
![]() |
95 ms | 46 MB |
g++-13 | 3_large_1_0.txt |
![]() |
227 ms | 147 MB |
g++-13 | 3_large_1_1.txt |
![]() |
259 ms | 144 MB |
g++-13 | 3_large_1_2.txt |
![]() |
221 ms | 135 MB |
g++-13 | 3_large_1_3.txt |
![]() |
255 ms | 162 MB |
g++-13 | 3_large_1_4.txt |
![]() |
232 ms | 146 MB |
g++-13 | 4_huge_0_0.txt |
![]() |
250 ms | 147 MB |
g++-13 | 5_max_0_0.txt |
![]() |
211 ms | 132 MB |
clang++-18 | 0_sample_0.txt |
![]() |
7 ms | 4 MB |
clang++-18 | 0_sample_1.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 1_small_0_0.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 1_small_0_1.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 1_small_0_2.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 1_small_0_3.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 1_small_0_4.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 1_small_0_5.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 1_small_0_6.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 1_small_0_7.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 1_small_0_8.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 1_small_0_9.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 2_medium_0_0.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 2_medium_0_1.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 2_medium_0_2.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 2_medium_0_3.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 2_medium_0_4.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 2_medium_0_5.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 2_medium_0_6.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 2_medium_0_7.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 2_medium_0_8.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 2_medium_0_9.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 2_medium_1_0.txt |
![]() |
6 ms | 4 MB |
clang++-18 | 2_medium_1_1.txt |
![]() |
7 ms | 4 MB |
clang++-18 | 2_medium_1_2.txt |
![]() |
7 ms | 4 MB |
clang++-18 | 2_medium_1_3.txt |
![]() |
7 ms | 4 MB |
clang++-18 | 2_medium_1_4.txt |
![]() |
7 ms | 4 MB |
clang++-18 | 3_large_0_0.txt |
![]() |
99 ms | 48 MB |
clang++-18 | 3_large_0_1.txt |
![]() |
101 ms | 48 MB |
clang++-18 | 3_large_0_2.txt |
![]() |
96 ms | 47 MB |
clang++-18 | 3_large_0_3.txt |
![]() |
101 ms | 48 MB |
clang++-18 | 3_large_0_4.txt |
![]() |
101 ms | 47 MB |
clang++-18 | 3_large_1_0.txt |
![]() |
225 ms | 147 MB |
clang++-18 | 3_large_1_1.txt |
![]() |
257 ms | 145 MB |
clang++-18 | 3_large_1_2.txt |
![]() |
213 ms | 135 MB |
clang++-18 | 3_large_1_3.txt |
![]() |
255 ms | 163 MB |
clang++-18 | 3_large_1_4.txt |
![]() |
229 ms | 146 MB |
clang++-18 | 4_huge_0_0.txt |
![]() |
240 ms | 146 MB |
clang++-18 | 5_max_0_0.txt |
![]() |
207 ms | 131 MB |