結果

問題 No.1170 Never Want to Walk
ユーザー cookiedothcookiedoth
提出日時 2020-08-14 22:12:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 2,490 bytes
コンパイル時間 1,438 ms
コンパイル使用メモリ 135,328 KB
実行使用メモリ 15,204 KB
最終ジャッジ日時 2024-04-18 22:03:32
合計ジャッジ時間 5,035 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 127 ms
14,720 KB
testcase_28 AC 124 ms
14,720 KB
testcase_29 AC 134 ms
15,204 KB
testcase_30 AC 132 ms
14,976 KB
testcase_31 AC 129 ms
14,848 KB
testcase_32 AC 124 ms
14,720 KB
testcase_33 AC 127 ms
14,720 KB
testcase_34 AC 127 ms
15,104 KB
testcase_35 AC 129 ms
14,848 KB
testcase_36 AC 123 ms
14,720 KB
testcase_37 AC 121 ms
14,720 KB
testcase_38 AC 123 ms
15,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*

Code for problem C by cookiedoth
Generated 14 Aug 2020 at 04.04 PM


▅███████ ]▄▄▄▄▄▄▄ 
█████████▅▄▃ 
Il████████████████] 
◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤

o_O
-_-
~_^

*/

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) cerr << #a << " = " << a << endl
#define forn(i, n) for (int i = 0; i < n; ++i)

using namespace std;

template<class T> int chkmax(T &a, T b) {
	if (b > a) {
		a = b;
		return 1;
	}
	return 0;
}

template<class T> int chkmin(T &a, T b) {
	if (b < a) {
		a = b;
		return 1;
	}
	return 0;
}

template<class iterator> void output(iterator begin, iterator end, ostream& out = cerr) {
	while (begin != end) {
		out << (*begin) << " ";
		begin++;
	}
	out << endl;
}

template<class T> void output(T x, ostream& out = cerr) {
	output(x.begin(), x.end(), out);
}

void fast_io() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

const int mx = 2e5 + 228;
int n, a, b, x[mx], par[mx], sz[mx];
set<int> not_joined;

int get_root(int v) {
	return (par[v] == v ? v : par[v] = get_root(par[v]));
}

void join(int u, int v) {
	u = get_root(u);
	v = get_root(v);
	if (u != v) {
		par[u] = v;
		sz[v] += sz[u];
	}
}

void read() {
	cin >> n >> a >> b;
	for (int i = 0; i < n; ++i) {
		cin >> x[i];
	}
	iota(par, par + n, 0);
	fill(sz, sz + n, 1);
	for (int i = 0; i < n - 1; ++i) {
		not_joined.insert(i);
	}
}

void process() {
	for (int i = 0; i < n; ++i) {
		int L = lower_bound(x, x + n, x[i] - b) - x;
		int R = upper_bound(x, x + n, x[i] - a) - x;
		if (R > L) {
			join(i, L);
			while (true) {
				auto it = not_joined.lower_bound(L);
				if (it == not_joined.end() || (*it) >= R - 1) {
					break;
				} else {
					join(*it, (*it) + 1);
					not_joined.erase(it);
				}
			}
		}
	}
}

void print_ans() {
	for (int i = 0; i < n; ++i) {
		cout << sz[get_root(i)] << '\n';
	}
}

signed main() {
	fast_io();
	read();
	process();
	print_ans();
}
0