結果

問題 No.1170 Never Want to Walk
ユーザー 👑 deuteridayodeuteridayo
提出日時 2021-02-04 23:49:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,651 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 173,436 KB
実行使用メモリ 17,200 KB
最終ジャッジ日時 2023-09-13 20:16:20
合計ジャッジ時間 9,670 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
4,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 131 ms
16,404 KB
testcase_34 WA -
testcase_35 AC 131 ms
17,000 KB
testcase_36 AC 129 ms
16,496 KB
testcase_37 AC 130 ms
16,548 KB
testcase_38 AC 134 ms
17,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>
using namespace std;
// using namespace atcoder;
using lint = long long;
using graph = vector<vector<int>>;
#define endl '\n'
lint const mod = 1e9+7;
//long const mod = 998244353;
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool unite(int x, int 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) {
        return -par[root(x)];
    }
};

int main(){
    lint n,a,b;
    cin >> n >> a >> b;
    vector<lint>x(n);
    for(int i=0;i<n;i++)cin >> x[i];
    graph g(n);
    vector<int>tmp(n+1);
    for(int i=0;i<n;i++){
        auto lItr = lower_bound(x.begin(), x.end(), x[i]+a);
        auto rItr = upper_bound(x.begin(), x.end(), x[i] +b);
        int l = lItr - x.begin();
        int r = rItr - x.begin();
        tmp[l]++;
        tmp[r]--;
        g[i].push_back(l);
    }
    for(int i=1;i<n;i++){
        tmp[i] += tmp[i-1];
    }
    for(int i=1;i<n;i++){
        if(tmp[i] > 0 && tmp[i-1] > 0){
            g[i-1].push_back(i);
        }
    }
    UnionFind unif(n);
    for(int i=0;i<n;i++){
        for(int j: g[i]){
            unif.unite(i,j);
        }
    }
    for(int i=0;i<n;i++){
        cout << unif.size(i)<<endl;
    }

}

0