結果

問題 No.1170 Never Want to Walk
ユーザー wdpuyowdpuyo
提出日時 2020-09-23 08:00:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 3,692 bytes
コンパイル時間 2,966 ms
コンパイル使用メモリ 177,280 KB
実行使用メモリ 10,932 KB
最終ジャッジ日時 2023-09-09 19:50:31
合計ジャッジ時間 6,975 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 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,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 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 71 ms
10,860 KB
testcase_28 AC 70 ms
10,520 KB
testcase_29 AC 73 ms
10,916 KB
testcase_30 AC 72 ms
10,748 KB
testcase_31 AC 71 ms
10,616 KB
testcase_32 AC 67 ms
10,856 KB
testcase_33 AC 70 ms
10,412 KB
testcase_34 AC 69 ms
10,932 KB
testcase_35 AC 69 ms
10,764 KB
testcase_36 AC 67 ms
10,556 KB
testcase_37 AC 68 ms
10,584 KB
testcase_38 AC 70 ms
10,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define INF 1000000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(lp, vec.size()) cout << vec[lp] << " "; print(""); 
#define show(x) cerr << #x << " = " << x << "\n";
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
#define pb(x) emplace_back(x)
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

const int mod = 998244353;
class mint {
public:
	ll x;
	mint(ll x = 0) : x((x % mod + mod) % mod) {}
	mint operator-() const { 
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}
	friend ostream& operator<<(ostream& os, const mint& m){
		os << m.x;
		return os;
	}
};

ll modpow(ll a, ll n){
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

struct union_find{

	vl parent;
	vl sizes;

	void init(ll n) {
	rep(i, n) parent.push_back(i);
	rep(i, n) sizes.push_back(1);
	return;
	}

	ll root(ll n){
	if(parent[n] == n) return n;
	return parent[n] = root(parent[n]);
	}

	ll size(ll n) {
	return sizes[root(n)];
	}

	bool is_same(ll a, ll b){
	return root(a) == root(b);
	}

	void unite(ll a, ll b){
	if(is_same(a, b)) return;
	sizes[root(a)] += size(b);
	parent[root(b)] = root(a);
	return;
	}
};


/* 
arg = 0: 「以下」のインデックス
arg = 1: 「未満」のインデックス
arg = 2: 「以上」のインデックス
arg = 3: 「より大きい」のインデックス
*/
ll binary_cnt(vl& v, ll key, ll arg){
	
	if(arg == 0){
		auto itr = upper_bound(ALL(v), key);
		ll num = itr - v.begin();
		return num - 1;
	}
	if(arg == 1){
		auto itr = lower_bound(ALL(v), key);
		ll num = itr - v.begin();
		return num - 1;
	}
	if(arg == 2){
		auto itr = lower_bound(ALL(v), key);
		ll num = v.end() - itr;
		return v.size() - num;
	}
	else{
		auto itr = upper_bound(ALL(v), key);
		ll num = v.end() - itr;
		return v.size() - num;
	}
	
}	

void Main(){

	ll N, A, B;
	cin >> N >> A >> B;
	vl v(N);
	rep(i, N) cin >> v[i];
	vl imos(N + 10);
	union_find uf;
	uf.init(N);
	
	rep(i, N){
		ll l = binary_cnt(v, v[i] + A, 2);
		ll r = binary_cnt(v, v[i] + B, 0);
		if(l > r) continue;
		uf.unite(i, l);
		imos[l] += 1;
		imos[r] -= 1;
	}

	rep(i, N) imos[i + 1] += imos[i];
	rep(i, N - 1) if(imos[i]) uf.unite(i, i + 1);
	rep(i, N) print(uf.size(i));

}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t = 1;
	//cin >> t;
	rep(i, t) Main();
	return 0;
	
}



0