結果

問題 No.1170 Never Want to Walk
ユーザー risujirohrisujiroh
提出日時 2020-08-14 21:33:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,622 bytes
コンパイル時間 3,330 ms
コンパイル使用メモリ 262,184 KB
実行使用メモリ 6,236 KB
最終ジャッジ日時 2023-07-31 21:24:47
合計ジャッジ時間 7,159 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 83 ms
5,924 KB
testcase_28 AC 81 ms
5,872 KB
testcase_29 AC 84 ms
6,220 KB
testcase_30 AC 84 ms
6,144 KB
testcase_31 AC 81 ms
6,016 KB
testcase_32 AC 71 ms
5,920 KB
testcase_33 AC 77 ms
6,144 KB
testcase_34 AC 74 ms
6,140 KB
testcase_35 AC 73 ms
6,236 KB
testcase_36 AC 69 ms
5,956 KB
testcase_37 AC 71 ms
5,976 KB
testcase_38 AC 74 ms
6,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>

#ifndef DUMP
#define DUMP(...) (void)0
#endif

using namespace std;

struct dsu {
  int cc;
  vector<int> p, sz;
  dsu(int n = 0) : cc(n), p(n, -1), sz(n, 1) {}
  int root(int v) {
    if (p[v] == -1) return v;
    return p[v] = root(p[v]);
  }
  bool unite(int u, int v) {
    u = root(u), v = root(v);
    if (u == v) return false;
    --cc;
    if (sz[u] < sz[v]) swap(u, v);
    p[v] = u;
    sz[u] += sz[v];
    return true;
  }
  bool same(int u, int v) { return root(u) == root(v); }
  int size(int v) { return sz[root(v)]; }
};

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> x(n);
  for (auto&& e : x) cin >> e;
  vector<int> cum(n);
  dsu d(n);
  auto f = [&](int i, int from, int to) {
    if (from > to) return;
    if (from == n) return;
    if (to == -1) return;
    from = max(from, 0);
    to = min(to, n - 1);
    ++cum[from];
    --cum[to];
    d.unite(i, from);
    d.unite(i, to);
  };
  for (int i = 0; i < n; ++i) {
    {
      int from = lower_bound(begin(x), end(x), x[i] + a) - begin(x);
      int to = upper_bound(begin(x), end(x), x[i] + b) - begin(x) - 1;
      f(i, from, to);
    }
    {
      int from = lower_bound(begin(x), end(x), x[i] - b) - begin(x);
      int to = upper_bound(begin(x), end(x), x[i] - a) - begin(x) - 1;
      f(i, from, to);
    }
  }
  DUMP(cum);
  for (int i = 0; i < n - 1; ++i) cum[i + 1] += cum[i];
  DUMP(cum);
  for (int i = 0; i < n - 1; ++i) {
    if (cum[i] == 0) continue;
    d.unite(i, i + 1);
  }
  for (int i = 0; i < n; ++i) {
    cout << d.size(i) << '\n';
  }
}
0