結果

問題 No.1170 Never Want to Walk
ユーザー yudedakoyudedako
提出日時 2020-08-22 18:05:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 1,498 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 110,196 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 11:57:12
合計ジャッジ時間 5,021 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 108 ms
5,376 KB
testcase_28 AC 107 ms
5,376 KB
testcase_29 AC 113 ms
5,376 KB
testcase_30 AC 110 ms
5,376 KB
testcase_31 AC 109 ms
5,376 KB
testcase_32 AC 102 ms
5,376 KB
testcase_33 AC 105 ms
5,376 KB
testcase_34 AC 102 ms
5,376 KB
testcase_35 AC 101 ms
5,376 KB
testcase_36 AC 100 ms
5,376 KB
testcase_37 AC 101 ms
5,376 KB
testcase_38 AC 104 ms
5,376 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