結果

問題 No.1170 Never Want to Walk
ユーザー YamagenSakamYamagenSakam
提出日時 2020-08-14 22:49:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,619 bytes
コンパイル時間 1,205 ms
コンパイル使用メモリ 113,016 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-04-18 22:40:04
合計ジャッジ時間 7,185 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 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 4 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 9 ms
5,376 KB
testcase_23 AC 5 ms
5,376 KB
testcase_24 AC 8 ms
5,376 KB
testcase_25 AC 8 ms
5,376 KB
testcase_26 AC 7 ms
5,376 KB
testcase_27 AC 310 ms
7,808 KB
testcase_28 AC 308 ms
7,552 KB
testcase_29 AC 306 ms
7,936 KB
testcase_30 AC 310 ms
7,808 KB
testcase_31 AC 317 ms
7,808 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

class union_find
{
private:
    std::vector<int> parent;
    std::vector<int> rank;
    vll size;
    int node_num;
public:
    union_find(int node_num);
    void unite(int x, int y);
    int find(int x);
    ll get_size(int x);
};

union_find::union_find(int node_num) :
    parent(node_num + 1, 0),
    rank(node_num + 1, 0),
    node_num(node_num),
    size(node_num + 1, 1)
{
    for (int i = 0; i <= node_num; i++) {
        parent[i] = i;
    }
}

void union_find::unite(int x, int y) {
    int x_root = find(x);
    int y_root = find(y);
    if (x_root == y_root) return;
    if (rank[x_root] > rank[y_root]) {
        parent[y_root] = x_root;
        size[x_root] += size[y_root];
    }
    else {
        parent[x_root] = y_root;
        if (rank[x_root] == rank[y_root]) {
            rank[y_root]++;
        }
        size[y_root] += size[x_root];
    }
}
ll union_find::get_size(int x) {
    return size[find(x)];
}
int union_find::find(int x) {
    if (x != parent[x]) {
        parent[x] = find(parent[x]);
    }
    return parent[x];
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    ll A, B;
    cin >> N >> A >> B;
    vll x(N);
    rep(i, N) cin >> x[i];
    union_find uf(N);
    vector<bool> already(N, false);
    rep(i, N) {
        //if (already[i] == true) continue;
        //already[i] = true;
        auto it = lower_bound(x.begin(), x.end(), x[i] + A);
        int start = distance(x.begin(), it);
        it = upper_bound(x.begin(), x.end(), x[i] + B);
        int end = distance(x.begin(), it);
        REP(j, start, end) {
            //if (already[j] == true) continue;
            already[j] = true;
            uf.unite(i, j);
        }
        it = lower_bound(x.begin(), x.end(), x[i] - B);
        start = distance(x.begin(), it);
        it = upper_bound(x.begin(), x.end(), x[i] - A);
        end = distance(x.begin(), it);
        REP(j, start, end) {
            //if (already[j] == true) continue;
            already[j] = true;
            uf.unite(i, j);
        }
    }
    rep(i, N) {
        cout << uf.get_size(i) << endl;
    }
    return 0;
}
0