結果

問題 No.1170 Never Want to Walk
ユーザー 鴨志田卓鴨志田卓
提出日時 2023-08-02 22:53:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 978 bytes
コンパイル時間 1,941 ms
コンパイル使用メモリ 201,372 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-04-20 22:43:00
合計ジャッジ時間 5,918 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,948 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 112 ms
14,336 KB
testcase_28 AC 110 ms
14,208 KB
testcase_29 AC 121 ms
14,464 KB
testcase_30 AC 112 ms
14,336 KB
testcase_31 AC 112 ms
14,080 KB
testcase_32 AC 98 ms
14,848 KB
testcase_33 AC 105 ms
14,592 KB
testcase_34 AC 105 ms
15,076 KB
testcase_35 AC 100 ms
14,948 KB
testcase_36 AC 97 ms
14,848 KB
testcase_37 AC 100 ms
14,720 KB
testcase_38 AC 108 ms
15,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;
using pii = pair<int, int>;

int n, a, b, x[N], ans[N];
int q[N], h, t;

set<pii> s;

void bfs(int st) {
    h = t = 0;
    q[t ++] = st;
    s.erase({x[st], st});
    while(h < t) {
        int u = q[h ++];
        int lt = t;
        for(auto it = s.lower_bound({x[u] - b, -1}); it != s.end() && it->first <= x[u] - a; it ++)
            q[t ++] = it->second;
        for(auto it = s.lower_bound({x[u] + a, -1}); it != s.end() && it->first <= x[u] + b; it ++)
            q[t ++] = it->second;
        while(lt < t)
            s.erase({x[q[lt]], q[lt ++]});
    }
    for(int i = 0; i < t; i ++)
        ans[q[i]] = t;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> a >> b;
    for(int i = 1; i <= n; i ++) {
        cin >> x[i];
        s.insert({x[i], i});
    }

    for(int i = 1; i <= n; i ++) {
        if(!ans[i]) bfs(i);
        cout << ans[i] << "\n";
    }
}
0