結果

問題 No.1170 Never Want to Walk
ユーザー nikkukunnikkukun
提出日時 2020-08-14 21:57:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 307 ms / 2,000 ms
コード長 1,428 bytes
コンパイル時間 1,688 ms
コンパイル使用メモリ 165,504 KB
実行使用メモリ 6,016 KB
最終ジャッジ日時 2024-04-18 21:43:30
合計ジャッジ時間 7,360 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// 20:39 - 20:49
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

int pa[N], siz[N];
int Find(int x) {
	return x == pa[x] ? x : pa[x] = Find(pa[x]);
}

int x[N];

int main() {
	ios::sync_with_stdio(0);

	int n, a, b;
	cin >> n >> a >> b;

	for (int i = 1; i <= n; i++) {
		cin >> x[i];
		pa[i] = i;
		siz[i] = 1;
	}
	int p = 1; // [l, r]
	for (int i = 1; i <= n; i++) {
		int l = lower_bound(x + 1, x + n + 1, x[i] + a) - x;
		p = max(l, p);
		while (p <= n && x[p] <= x[i] + b) {
			int pa1 = Find(i);
			int pa2 = Find(p);
			if (pa1 != pa2) {
				siz[pa1] += siz[pa2];
				pa[pa2] = pa[pa1];
			}
			p++;
		}
		p--;
	}

	for (int i = 1; i <= n; i++)
		x[i] = int(1e9) - x[i];
	reverse(x + 1, x + n + 1);

	p = 1;
	for (int i = 1; i <= n; i++) {
		int l = lower_bound(x + 1, x + n + 1, x[i] + a) - x;
		p = max(l, p);
		while (p <= n && x[p] <= x[i] + b) {
			int pa1 = Find(n - i + 1);
			int pa2 = Find(n - p + 1);
			if (pa1 != pa2) {
				siz[pa1] += siz[pa2];
				pa[pa2] = pa[pa1];
			}
			p++;
		}
		p--;
	}

	for (int i = 1; i <= n; i++)
		cout << siz[Find(i)] << endl;

	return 0;
}
0