結果

問題 No.1170 Never Want to Walk
ユーザー leaf_1415
提出日時 2020-08-14 21:44:29
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 1,998 bytes
コンパイル時間 912 ms
コンパイル使用メモリ 96,356 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-10-10 14:50:30
合計ジャッジ時間 4,382 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

llint n, a, b;
llint x[200005];
set<P> S;
UnionFind uf(200005);
map<llint, llint> mp;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> a >> b;
	for(int i = 1; i <= n; i++) cin >> x[i];
	
	for(llint i = 1; i <= n; i++){
		auto it = S.lower_bound(P(x[i]-b, -inf));
		llint mn = inf, mx = -inf;
		for(;it != S.end() && it->first <= x[i]-a; it++){
			uf.unite(it->second, i);
			mn = min(mn, it->second), mx = max(mx, it->second);
		}
		it = S.lower_bound(P(x[i]-b, -inf));
		for(;it != S.end() && it->first <= x[i]-a;){
			//cout << "D " << it->first << endl;
			auto tmp = it;
			it++;
			S.erase(tmp);
		}
		if(mn < inf/2){
			S.insert(P(x[mn], mn));
			S.insert(P(x[mx], mx));
			//cout << mn << " " << mx << endl;
		}
		S.insert(P(x[i], i));
	}
	
	for(int i = 1; i <= n; i++) mp[uf.root(i)]++;
	for(int i = 1; i <= n; i++) cout << mp[uf.root(i)] << "\n";
	flush(cout);
	
	return 0;
}
0