結果

問題 No.1170 Never Want to Walk
ユーザー spihillspihill
提出日時 2021-01-09 18:37:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 367 ms / 2,000 ms
コード長 914 bytes
コンパイル時間 2,191 ms
コンパイル使用メモリ 204,044 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 07:25:41
合計ジャッジ時間 8,403 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 346 ms
5,376 KB
testcase_28 AC 336 ms
5,376 KB
testcase_29 AC 349 ms
5,376 KB
testcase_30 AC 344 ms
5,376 KB
testcase_31 AC 335 ms
5,376 KB
testcase_32 AC 339 ms
5,376 KB
testcase_33 AC 342 ms
5,376 KB
testcase_34 AC 351 ms
5,376 KB
testcase_35 AC 350 ms
5,376 KB
testcase_36 AC 332 ms
5,376 KB
testcase_37 AC 345 ms
5,376 KB
testcase_38 AC 367 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
struct UF {
    vector<int> par;
    UF(int n) : par(n, -1) {}
    int root(int v) {
        if (par[v] < 0) return v;
        return par[v] = root(par[v]);
    }
    int size(int v) {
        return -par[root(v)];
    }
    void unite(int u, int v) {
        u = root(u);
        v = root(v);
        if (u == v) return;
        par[u] += par[v];
        par[v] = u;
    }
};

int main() {
    int N, A, B; cin >> N >> A >> B;
    vector<int> v(N); for (auto& x : v) cin >> x;
    UF uf(N);
    for (int i = 0, l = 0, r = 0; i < N; i++) {
        while (l < N && v[l] < v[i] - B) l++;
        while (l < N && v[l] <= v[i] - A) uf.unite(i, l++);
        l = max(l-1, 0);
        while (r < N && v[r] < v[i] + A) r++;
        while (r < N && v[r] <= v[i] + B) uf.unite(i, r++);
        r = max(r-1, 0);
    }
    for (int i = 0; i < N; i++) cout << uf.size(i) << endl;
}
0