結果

問題 No.1170 Never Want to Walk
ユーザー FF256grhyFF256grhy
提出日時 2020-08-14 21:47:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 373 ms / 2,000 ms
コード長 4,553 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 207,120 KB
実行使用メモリ 17,628 KB
最終ジャッジ日時 2023-07-31 21:54:08
合計ジャッジ時間 8,900 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 4 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 364 ms
16,172 KB
testcase_28 AC 360 ms
16,376 KB
testcase_29 AC 373 ms
16,660 KB
testcase_30 AC 372 ms
17,432 KB
testcase_31 AC 364 ms
16,716 KB
testcase_32 AC 362 ms
17,016 KB
testcase_33 AC 365 ms
16,892 KB
testcase_34 AC 360 ms
17,348 KB
testcase_35 AC 364 ms
17,280 KB
testcase_36 AC 359 ms
17,628 KB
testcase_37 AC 348 ms
17,088 KB
testcase_38 AC 366 ms
17,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
// 以下、入出力関係のテンプレ案のテスト
auto * IS = & cin;
// input elements (as a tuple)
template<typename U, int I> void in_(U & t) { }
template<typename U, int I, typename A, typename ... B> void in_(U & t) { (* IS) >> get<I>(t); in_<U, I + 1, B ...>(t); }
template<typename ... T> auto in() { tuple<T ...> t; in_<tuple<T ...>, 0, T ...>(t); return t; }
// input a array
template<typename T, int N> auto ain() { array<T, N> a; inc(i, N) { (* IS) >> a[i]; } return a; }
// input a (multi-dimensional) vector
template<typename T> T vin() { return * istream_iterator<T>(* IS); }
template<typename T, typename N, typename ... M> auto vin(N n, M ... m) {
	vector<decltype(vin<T, M ...>(m ...))> v(n); inc(i, n) { v[i] = vin<T, M ...>(m ...); } return v;
}
// input multi-column (as a tuple of vector)
template<typename U, int I> void colin_(U & t) { }
template<typename U, int I, typename A, typename ... B> void colin_(U & t) {
	get<I>(t).emplace_back(* istream_iterator<A>(* IS)); colin_<U, I + 1, B ...>(t);
}
template<typename ... T> auto colin(int n) {
	tuple<vector<T> ...> t; inc(i, n) { colin_<tuple<vector<T> ...>, 0, T ...>(t); } return t;
}
auto * OS = & cout;
string SP = " ", LN = "\n";
// output elements
void out() { (* OS) << LN << flush; }
template<typename A                > void out(A && a            ) { (* OS) << a      ; out(     ); }
template<typename A, typename ... B> void out(A && a, B && ... b) { (* OS) << a << SP; out(b ...); }
// output a (multi-dimensional) vector
template<typename T> ostream & operator<<(ostream & os, vector<T> const & v) {
	inc(i, v.size()) { os << (i == 0 ? "" : SP) << v[i]; } return os << flush;
}
template<typename T> void vout_(T && v) { (* OS) << v; }
template<typename T, typename A, typename ... B> void vout_(T && v, A a, B ... b) {
	for(auto && w: v) { vout_(w, b ...); (* OS) << a; }
}
template<typename T, typename ... A> void vout(T && v, A ... a) { vout_(v, a ...); out(); }

// ---- ----

class UnionFind {
private:
	int n, s;
	vector<int> t;
	vector<vector<int>> v;
public:
	UnionFind(int arg_n = 0) { init(arg_n); }
	void init(int arg_n) {
		n = s = arg_n;
		t.clear();
		v.clear();
		inc(i, n) { t.PB(i); v.EB(1, i); }
	}
	int get_n() { return n; }
	int size() { return s; }
	int id(int x) { return t.at(x); }
	const vector<vector<int>> & get_v() { return v; }
	bool unite(int x, int y) {
		x = id(x);
		y = id(y);
		if(x == y) { return false; }
		if(v[x].size() < v[y].size()) { swap(x, y); }
		for(auto & e: v[y]) { v[x].PB(e); t[e] = x; }
		v[y].clear();
		s--;
		return true;
	}
	bool same(int x, int y) { return (id(x) == id(y)); }
	const vector<int> & operator[](int x) { return v[id(x)]; }
	friend ostream & operator<<(ostream & os, const UnionFind & uf) {
		inc(i, uf.n) { os << i << ": "; for(auto & e: uf.v[i]) { os << e << " "; } os << "\n"; }
		return os;
	}
};

// ---- ----

#define LB(v, x) (lower_bound(ALL(v), x) - v.begin())
#define UB(v, x) (upper_bound(ALL(v), x) - v.begin())

int main() {
	auto [n, a, b] = ain<int, 3>();
	auto x = vin<int>(n);
	
	UnionFind uf(n);
	int p = 0;
	inc(i, n) {
		int L = LB(x, x[i] + a);
		int R = UB(x, x[i] + b);
		if(setmax(L, p)) { uf.unite(i, i - 1); }
		incID(j, L, R) { uf.unite(i, j); }
		p = R;
	}
	inc(i, n) { out(SI(uf[i])); }
}
0