結果

問題 No.1170 Never Want to Walk
ユーザー Mr.SpockMr.Spock
提出日時 2020-12-15 14:43:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 486 ms / 2,000 ms
コード長 1,176 bytes
コンパイル時間 3,125 ms
コンパイル使用メモリ 176,112 KB
実行使用メモリ 33,784 KB
最終ジャッジ日時 2023-10-20 06:00:53
合計ジャッジ時間 12,048 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,624 KB
testcase_01 AC 4 ms
4,624 KB
testcase_02 AC 4 ms
4,624 KB
testcase_03 AC 3 ms
4,624 KB
testcase_04 AC 3 ms
4,624 KB
testcase_05 AC 3 ms
4,624 KB
testcase_06 AC 4 ms
4,624 KB
testcase_07 AC 3 ms
4,624 KB
testcase_08 AC 3 ms
4,624 KB
testcase_09 AC 3 ms
4,624 KB
testcase_10 AC 4 ms
4,624 KB
testcase_11 AC 3 ms
4,624 KB
testcase_12 AC 5 ms
4,624 KB
testcase_13 AC 5 ms
4,624 KB
testcase_14 AC 5 ms
4,624 KB
testcase_15 AC 5 ms
4,624 KB
testcase_16 AC 5 ms
4,624 KB
testcase_17 AC 5 ms
4,624 KB
testcase_18 AC 5 ms
4,624 KB
testcase_19 AC 5 ms
4,624 KB
testcase_20 AC 5 ms
4,624 KB
testcase_21 AC 5 ms
4,624 KB
testcase_22 AC 5 ms
5,008 KB
testcase_23 AC 5 ms
5,008 KB
testcase_24 AC 5 ms
5,008 KB
testcase_25 AC 5 ms
5,008 KB
testcase_26 AC 5 ms
5,008 KB
testcase_27 AC 457 ms
29,032 KB
testcase_28 AC 459 ms
29,560 KB
testcase_29 AC 445 ms
26,128 KB
testcase_30 AC 468 ms
29,560 KB
testcase_31 AC 448 ms
28,240 KB
testcase_32 AC 471 ms
32,728 KB
testcase_33 AC 477 ms
32,200 KB
testcase_34 AC 481 ms
33,256 KB
testcase_35 AC 472 ms
32,992 KB
testcase_36 AC 457 ms
32,464 KB
testcase_37 AC 463 ms
32,464 KB
testcase_38 AC 486 ms
33,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int nax = 2e5 + 7;
vector<int>par(nax);
vector<int>siz(nax, 1);
int get(int x) {
	if (x == par[x])return x;
	return (par[x]) = get(par[x]);
}
void unite(int x, int y) {
	x = get(x);
	y = get(y);
	if (x == y)return ;
	if (siz[y] > siz[x])swap(x, y);
	par[y] = x;
	siz[x] += siz[y];
}
void foo() {
	iota(par.begin(), par.end(), 0);
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	foo();
	int n, a, b;
	cin >> n >> a >> b;
	vector<int>v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	int lower = 0, upper = 0;
	set<pair<int, int>>s;
	for (int i = 0; i < n; i++) {
		int l = lower_bound(v.begin(), v.end(), v[i] + a) - v.begin();
		lower = max(lower, l);
		upper = upper_bound(v.begin(), v.end(), v[i] + b) - v.begin();
		if (upper != 0)upper--;
		for (int j = lower; j <= upper; j++) {
			s.insert({i, j});
		}
		lower = upper - 1;
	}
	for (auto k : s) {
		int x = k.first;
		int y = k.second;
		unite(x, y);
	}
	for (int i = 0; i < n; i++) {
		cout << siz[get(i)] << endl;
	}
}

0