結果

問題 No.1170 Never Want to Walk
ユーザー msm1993msm1993
提出日時 2020-09-11 16:23:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,498 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 120,188 KB
実行使用メモリ 4,716 KB
最終ジャッジ日時 2023-08-26 23:45:58
合計ジャッジ時間 6,907 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 112 ms
4,556 KB
testcase_28 AC 109 ms
4,580 KB
testcase_29 AC 114 ms
4,716 KB
testcase_30 AC 114 ms
4,564 KB
testcase_31 AC 111 ms
4,624 KB
testcase_32 AC 101 ms
4,564 KB
testcase_33 AC 108 ms
4,600 KB
testcase_34 AC 104 ms
4,620 KB
testcase_35 AC 103 ms
4,572 KB
testcase_36 AC 100 ms
4,692 KB
testcase_37 AC 103 ms
4,696 KB
testcase_38 AC 105 ms
4,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>
#include <complex>

class UnionFind {
	std::vector<int> vec;
public:
	UnionFind(int size) : vec(size, -1) {};
	int find(int a) {
		return vec[a] < 0 ? a : vec[a] = find(vec[a]);
	}
	int size_of(int a) {
		return -vec[find(a)];
	}
	void unite(int a, int b) {
		a = find(a);
		b = find(b);
		if (a == b) return;
		if (vec[a] > vec[b]) std::swap(a, b);
		vec[a] += vec[b];
		vec[b] = a;
	}
};
int main() {
	int n, a, b; std::cin >> n >> a >> b;
	std::vector<int> stations(n); for (auto& s : stations) std::cin >> s;
	int right = 0;
	UnionFind uft(n);
	for (auto i = 0; i < n; ++i) {
		const auto s = stations[i];
		const auto begin = std::distance(stations.begin(), std::lower_bound(stations.begin(), stations.end(), s + a));
		const auto end = std::distance(stations.begin(), std::upper_bound(stations.begin(), stations.end(), s + b));
		if (begin < right) {
			uft.unite(i, begin);
		}
		else {
			right = begin;
		}
		while (right < end) {
			uft.unite(i, right++);
		}
	}
	for (auto i = 0; i < n; ++i) {
		std::cout << uft.size_of(i) << '\n';
	}
}
0