結果

問題 No.1170 Never Want to Walk
ユーザー drken1215drken1215
提出日時 2020-08-14 21:41:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 363 ms / 2,000 ms
コード長 2,302 bytes
コンパイル時間 1,911 ms
コンパイル使用メモリ 169,660 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-04-18 21:16:39
合計ジャッジ時間 8,273 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 4 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 3 ms
5,376 KB
testcase_27 AC 353 ms
5,760 KB
testcase_28 AC 342 ms
5,504 KB
testcase_29 AC 359 ms
5,632 KB
testcase_30 AC 363 ms
5,504 KB
testcase_31 AC 348 ms
5,632 KB
testcase_32 AC 337 ms
5,632 KB
testcase_33 AC 347 ms
5,760 KB
testcase_34 AC 351 ms
5,504 KB
testcase_35 AC 361 ms
5,504 KB
testcase_36 AC 340 ms
5,632 KB
testcase_37 AC 355 ms
5,632 KB
testcase_38 AC 354 ms
5,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


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 issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(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() {
    int N;
    long long A, B;
    cin >> N >> A >> B;
    vector<long long> x(N);
    for (int i = 0; i < N; ++i) cin >> x[i];

    int prev = 0;
    UnionFind uf(N);
    for (int i = 0; i < N; ++i) {
        int left = lower_bound(x.begin(), x.end(), x[i] + A) - x.begin();
        int right = upper_bound(x.begin(), x.end(), x[i] + B) - x.begin();
        if (left < prev) uf.merge(i-1, i);
        for (int j = max(left, prev); j < right; ++j) {
            uf.merge(i, j);
        }
        prev = right;
    }
    for (int i = 0; i < N; ++i) {
        cout << uf.size(i) << endl;
    }

}















0