結果

問題 No.1170 Never Want to Walk
ユーザー furafura
提出日時 2020-09-06 01:44:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,112 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 203,048 KB
実行使用メモリ 5,548 KB
最終ジャッジ日時 2023-08-19 13:20:47
合計ジャッジ時間 6,045 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 3 ms
4,376 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,380 KB
testcase_27 AC 92 ms
5,548 KB
testcase_28 AC 90 ms
5,184 KB
testcase_29 AC 93 ms
5,452 KB
testcase_30 AC 92 ms
5,384 KB
testcase_31 AC 91 ms
5,176 KB
testcase_32 AC 80 ms
5,376 KB
testcase_33 AC 87 ms
5,184 KB
testcase_34 AC 82 ms
5,380 KB
testcase_35 AC 82 ms
5,436 KB
testcase_36 AC 80 ms
5,112 KB
testcase_37 AC 80 ms
5,472 KB
testcase_38 AC 83 ms
5,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class union_find{
	int n;
	vector<int> p;
public:
	union_find(int n):n(n),p(n,-1){}
	int find(int u){ return p[u]<0?u:p[u]=find(p[u]); }
	void unite(int u,int v){
		u=find(u); v=find(v);
		if(u!=v){
			if(p[v]<p[u]) swap(u,v);
			p[u]+=p[v]; p[v]=u; n--;
		}
	}
	bool is_same(int u,int v){ return find(u)==find(v); }
	int size()const{ return n; }
	int size(int u){ return -p[find(u)]; }
};

int main(){
	int n,a,b; scanf("%d%d%d",&n,&a,&b);
	vector<int> x(n);
	rep(i,n) scanf("%d",&x[i]);

	union_find U(n);
	vector<int> sum(n+1);
	rep(i,n){
		int l=lower_bound(x.begin(),x.end(),x[i]+a)-x.begin();
		int r=upper_bound(x.begin(),x.end(),x[i]+b)-x.begin();
		if(l<r-1){
			sum[l]++;
			sum[r-1]--;
		}
		if(l<r) U.unite(i,l);

		l=lower_bound(x.begin(),x.end(),x[i]-b)-x.begin();
		r=upper_bound(x.begin(),x.end(),x[i]-a)-x.begin();
		if(l<r-1){
			sum[l]++;
			sum[r-1]--;
		}
		if(l<r) U.unite(i,l);
	}

	rep(i,n) sum[i+1]+=sum[i];
	rep(i,n) if(sum[i]>0) U.unite(i,i+1);

	rep(i,n) printf("%d\n",U.size(i));

	return 0;
}
0