結果
| 問題 | 
                            No.1170 Never Want to Walk
                             | 
                    
| コンテスト | |
| ユーザー | 
                             poohbear
                         | 
                    
| 提出日時 | 2020-08-14 23:19:57 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,741 bytes | 
| コンパイル時間 | 2,214 ms | 
| コンパイル使用メモリ | 197,676 KB | 
| 最終ジャッジ日時 | 2025-01-13 00:44:56 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 WA * 1 | 
| other | AC * 13 WA * 17 TLE * 7 | 
ソースコード
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
using Graph = vector<vector<ll> >;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
//UnionFind
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
    UnionFind(int n) : par(n, -1) { }
    int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool merge(int x, int y) {//xの木とyの木を結合する
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    int size(int x) {//sizeの取得
        return -par[root(x)];
    }
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
//input
ll n,a,b;
vector<ll>x;
int main(){
    cin >> n >> a >> b;
    x.resize(n);
    rep(i,n)cin>>x[i];
    UnionFind u(n+1);
    for(int i=n-1;i>=0;i--){
        ll r = lower_bound(x.begin(),x.end(),x[i]+b)-x.begin();
        ll l = lower_bound(x.begin(),x.end(),x[i]+a)-x.begin();
        if(l==n)continue;
        for(int j=l;j<r;j++){
            u.merge(i,j);
        }
    }
    rep(i,n){
        cout << u.size(i) << endl;
    }
    return 0;
}
            
            
            
        
            
poohbear