結果

問題 No.1170 Never Want to Walk
ユーザー chocoruskchocorusk
提出日時 2020-08-14 21:42:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 401 ms / 2,000 ms
コード長 1,615 bytes
コンパイル時間 1,282 ms
コンパイル使用メモリ 126,340 KB
最終ジャッジ日時 2025-01-12 23:28:06
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
struct unionfind{
    vector<int> par, sz;
    unionfind() {}
    unionfind(int n):par(n), sz(n, 1){
        for(int i=0; i<n; i++) par[i]=i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void unite(int x, int y){
        x=find(x); y=find(y);
        if(x==y) return;
        if(sz[x]>sz[y]) swap(x, y);
        par[x]=y;
        sz[y]+=sz[x];
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};
int main()
{
	int n;
	ll a, b;
	cin>>n>>a>>b;
	ll x[200020];
	for(int i=0; i<n; i++){
		cin>>x[i];
	}
	int l[200020], r[200020];
	for(int i=0; i<n; i++){
		l[i]=lower_bound(x, x+n, x[i]+a)-x;
		r[i]=upper_bound(x, x+n, x[i]+b)-x;
	}
	unionfind uf(n);
	int pr=0;
	for(int i=0; i<n; i++){
		if(i==n-1 || r[i]<=l[i+1]){
			for(int j=pr; j<i; j++) uf.unite(j, j+1);
			for(int j=l[pr]; j<r[i]-1; j++) uf.unite(j, j+1);
			if(l[pr]<r[pr]) uf.unite(pr, l[pr]);
			pr=i+1;
		}
	}
	for(int i=0; i<n; i++){
		cout<<uf.size(i)<<endl;
	}
	return 0;
}
0