結果

問題 No.1170 Never Want to Walk
ユーザー Example0911Example0911
提出日時 2020-08-15 08:52:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 302 ms / 2,000 ms
コード長 1,835 bytes
コンパイル時間 1,601 ms
コンパイル使用メモリ 170,144 KB
実行使用メモリ 9,380 KB
最終ジャッジ日時 2023-08-01 00:52:46
合計ジャッジ時間 7,619 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,384 KB
testcase_13 AC 4 ms
4,384 KB
testcase_14 AC 3 ms
4,384 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,384 KB
testcase_19 AC 3 ms
4,384 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 4 ms
4,384 KB
testcase_25 AC 3 ms
4,384 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 297 ms
9,116 KB
testcase_28 AC 296 ms
9,232 KB
testcase_29 AC 302 ms
9,100 KB
testcase_30 AC 296 ms
9,240 KB
testcase_31 AC 300 ms
9,188 KB
testcase_32 AC 293 ms
9,052 KB
testcase_33 AC 289 ms
9,132 KB
testcase_34 AC 294 ms
9,044 KB
testcase_35 AC 293 ms
9,116 KB
testcase_36 AC 288 ms
9,184 KB
testcase_37 AC 289 ms
9,124 KB
testcase_38 AC 301 ms
9,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

// コンテスト中のみ
//#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
int MOD = 1000000007;
const ll INF = 1LL << 60;

class UnionFind {
public:
	vector <ll> par; // 各元の親を表す配列
	vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.resize(sz_, 1);
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		// merge technique(データ構造をマージするテク.小を大にくっつける)
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}
};

ll N, A, B;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> N >> A >> B;
	vector<ll>x(N); rep(i, N)cin >> x[i];
	UnionFind uf(N);
	vector<ll>imos(N);
	rep(i, N) {
		ll l = lower_bound(x.begin(), x.end(), x[i] + A) - x.begin();
		ll r = upper_bound(x.begin(), x.end(), x[i] + B) - x.begin() - 1;
		if (l > r)continue;
		uf.merge(i, l);
		imos[l]++; imos[r]--;
	}
	rep(i, N - 1)imos[i + 1] += imos[i];
	rep(i, N - 1) {
		if (imos[i]) {
			uf.merge(i, i + 1);
		}
	}
	rep(i, N) {
		cout << uf.size(i) << endl;
	}
	return 0;
}
0