結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,704 KB
testcase_01 AC 3 ms
4,704 KB
testcase_02 AC 3 ms
4,704 KB
testcase_03 AC 3 ms
4,704 KB
testcase_04 AC 3 ms
4,704 KB
testcase_05 AC 3 ms
4,704 KB
testcase_06 AC 3 ms
4,704 KB
testcase_07 AC 3 ms
4,704 KB
testcase_08 AC 4 ms
4,704 KB
testcase_09 AC 3 ms
4,704 KB
testcase_10 AC 3 ms
4,704 KB
testcase_11 AC 3 ms
4,704 KB
testcase_12 AC 5 ms
4,704 KB
testcase_13 AC 5 ms
4,704 KB
testcase_14 AC 5 ms
4,704 KB
testcase_15 AC 5 ms
4,704 KB
testcase_16 AC 5 ms
4,704 KB
testcase_17 AC 5 ms
4,704 KB
testcase_18 AC 5 ms
4,704 KB
testcase_19 AC 5 ms
4,704 KB
testcase_20 AC 5 ms
4,704 KB
testcase_21 AC 4 ms
4,704 KB
testcase_22 AC 5 ms
5,088 KB
testcase_23 AC 5 ms
5,088 KB
testcase_24 AC 5 ms
5,088 KB
testcase_25 AC 5 ms
5,088 KB
testcase_26 AC 5 ms
5,088 KB
testcase_27 AC 453 ms
29,112 KB
testcase_28 AC 450 ms
29,640 KB
testcase_29 AC 435 ms
26,208 KB
testcase_30 AC 459 ms
29,640 KB
testcase_31 AC 442 ms
28,320 KB
testcase_32 AC 459 ms
32,808 KB
testcase_33 AC 476 ms
32,280 KB
testcase_34 AC 471 ms
33,336 KB
testcase_35 AC 467 ms
33,072 KB
testcase_36 AC 452 ms
32,544 KB
testcase_37 AC 458 ms
32,544 KB
testcase_38 AC 475 ms
33,864 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