結果

問題 No.1170 Never Want to Walk
ユーザー minatominato
提出日時 2020-08-14 21:44:53
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 2,473 bytes
コンパイル時間 3,721 ms
コンパイル使用メモリ 236,364 KB
実行使用メモリ 7,820 KB
最終ジャッジ日時 2024-04-18 21:24:46
合計ジャッジ時間 6,822 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 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 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 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 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 70 ms
7,740 KB
testcase_28 AC 69 ms
7,704 KB
testcase_29 AC 70 ms
7,788 KB
testcase_30 AC 70 ms
7,772 KB
testcase_31 AC 68 ms
7,720 KB
testcase_32 AC 64 ms
7,736 KB
testcase_33 AC 67 ms
7,708 KB
testcase_34 AC 65 ms
7,660 KB
testcase_35 AC 63 ms
7,644 KB
testcase_36 AC 63 ms
7,720 KB
testcase_37 AC 62 ms
7,736 KB
testcase_38 AC 67 ms
7,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

struct UnionFind {
    int N;
    vector<int> node;

    UnionFind(){}
    UnionFind(int N) : N(N), node(N,-1) {}

    void init(int x) {
        node.assign(x,-1);
        N = x;
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (node[x] > node[y]) swap(x,y);
        node[x] += node[y];
        node[y] = x;
        N--;
        return true; 
    }

    bool same(int x, int y) {return root(x) == root(y);}

    int root(int x) {
        if (node[x] < 0) return x;
        return node[x] = root(node[x]);
    }

    int size(int x) {return -node[root(x)];}

    int count() const {return N;}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,A,B; cin >> N >> A >> B;
    vector<ll> x(N);
    rep(i,N) cin >> x[i];

    UnionFind uf(N);
    vector<pii> C; 
    rep(i,N) {
        int l = lower_bound(all(x),x[i]+A) - x.begin();
        int r = upper_bound(all(x),x[i]+B) - x.begin();
        if (l < r) {
            uf.merge(i,l);
            C.emplace_back(l,r);
        }
    }
    int M = C.size();
    int cur = 0;
    int r = 0;
    rep(i,N) {
        while (cur < M and C[cur].first < i) {
            chmax(r,C[cur].second);
            cur++;
        }
        if (i < r) {
            uf.merge(i,i-1);
        }
    }

    rep(i,N) cout << uf.size(i) << ln;
}
0