結果

問題 No.1170 Never Want to Walk
ユーザー sirogamichan1sirogamichan1
提出日時 2020-08-14 22:01:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,515 bytes
コンパイル時間 1,955 ms
コンパイル使用メモリ 169,224 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-04-18 21:49:20
合計ジャッジ時間 6,938 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 270 ms
6,144 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;

int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};

struct UnionFind
{
	vector<long long> par;

	void init(long long n) {par.assign(n, -1);}

	long long root(long long x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool merge(long long x, long long y)
	{
		x = root(x);
		y = root(y);
		if(x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	bool issame(long long x, long long y)
	{
		return root(x) == root(y);
	}

	long long size(long long x)
	{
		return -par[root(x)];
	}
};


ll N, A, B;

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> A >> B;
	vector<ll> x(N);
	REP(i, N) cin >> x[i];

	UnionFind uf;
	uf.init(N);

	vector<bool> is(N, false);

	REP(i, N-1)
	{
		if (is[i]) continue;
		// for (ll j = i + 1; j < N; ++j)
		// {
		// 	ll t = abs(x[i] - x[j]);
		// 	if (A <= t && t <= B)
		// 		uf.merge(i, j);
		// }

		auto b = lower_bound(ALL(x), x[i] + A) - x.begin();
		auto e = upper_bound(ALL(x), x[i] + B) - x.begin();
		
		for (ll j = b; j < e; ++j)
		{
			uf.merge(i, j);
			is[j] = true;
		}
	}

	REP(i, N)
		std::cout << uf.size(i) << std::endl;

	
	return 0;
}
0