結果

問題 No.1170 Never Want to Walk
ユーザー sirogamichan1sirogamichan1
提出日時 2020-08-15 09:41:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 310 ms / 2,000 ms
コード長 1,447 bytes
コンパイル時間 1,516 ms
コンパイル使用メモリ 171,632 KB
実行使用メモリ 8,128 KB
最終ジャッジ日時 2023-08-01 00:55:39
合計ジャッジ時間 7,421 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,384 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,384 KB
testcase_27 AC 297 ms
7,972 KB
testcase_28 AC 296 ms
7,864 KB
testcase_29 AC 310 ms
8,080 KB
testcase_30 AC 305 ms
8,048 KB
testcase_31 AC 293 ms
7,948 KB
testcase_32 AC 297 ms
7,988 KB
testcase_33 AC 294 ms
8,128 KB
testcase_34 AC 299 ms
8,020 KB
testcase_35 AC 294 ms
8,052 KB
testcase_36 AC 292 ms
7,944 KB
testcase_37 AC 287 ms
7,908 KB
testcase_38 AC 304 ms
8,092 KB
権限があれば一括ダウンロードができます

ソースコード

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);
	vector<ll> y(N, 0);

	REP(i, N-1)
	{
		auto l = lower_bound(ALL(x), x[i] + A) - x.begin();
		auto r = upper_bound(ALL(x), x[i] + B) - x.begin() - 1;
		if (l > r) continue;
		uf.merge(i, l);
		++y[l], --y[r];
	}

	REP(i, N-1)
		y[i+1] += y[i];

	REP(i, N-1)
		if (y[i] > 0)
			uf.merge(i, i+1);

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

	exit(0);
}
0