結果

問題 No.1170 Never Want to Walk
ユーザー risujirohrisujiroh
提出日時 2020-08-14 21:31:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,583 bytes
コンパイル時間 3,713 ms
コンパイル使用メモリ 255,260 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-04-18 20:47:29
合計ジャッジ時間 8,742 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,760 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
6,940 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
6,944 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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 == n) return;
    if (to == -1) return;
    from = max(from, 0);
    to = min(to, n - 1);
    for (int j = from; j < to; ++j) ++cum[j];
    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);
    }
  }
  for (int i = 0; i < n - 1; ++i) cum[i + 1] += cum[i];
  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