結果

問題 No.1170 Never Want to Walk
ユーザー MayimgMayimg
提出日時 2020-08-17 17:14:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,569 bytes
コンパイル時間 2,039 ms
コンパイル使用メモリ 204,272 KB
実行使用メモリ 6,388 KB
最終ジャッジ日時 2023-08-01 19:57:03
合計ジャッジ時間 5,240 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 61 ms
5,940 KB
testcase_28 AC 60 ms
6,008 KB
testcase_29 AC 64 ms
6,152 KB
testcase_30 AC 62 ms
6,208 KB
testcase_31 AC 61 ms
5,884 KB
testcase_32 AC 57 ms
5,964 KB
testcase_33 AC 60 ms
6,028 KB
testcase_34 AC 58 ms
6,148 KB
testcase_35 AC 58 ms
6,144 KB
testcase_36 AC 56 ms
6,196 KB
testcase_37 AC 56 ms
5,888 KB
testcase_38 AC 59 ms
6,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

/////////////////////////////////////////////////////////////////////////
// UNION FIND
/////////////////////////////////////////////////////////////////////////
class UnionFind {
private:
  int siz;
  vector<int> a;

public:
  UnionFind(int x) : siz(x), a(x, -1) {}

  int root(int x) {
    return a[x] < 0 ? x : a[x] = root(a[x]);
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    siz--;
    if (a[x] > a[y]) swap(x, y);
    a[x] += a[y];
    a[y] =x;
    return true;
  }

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

  int size(int x) {
    return -a[root(x)];
  }
  
  int connected_component() {
  	return siz;
  }
};
/////////////////////////////////////////////////////////////////////////
// END UNION FIND
/////////////////////////////////////////////////////////////////////////

signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  vector<long long> v(n);
  for (auto& x : v) cin >> x;
  UnionFind uf(n);
  vector<int> w(n);
  for (int i = 0; i < n; i++) {
    int l = lower_bound(v.begin(), v.end(), v[i] + a) - v.begin();
    int r = prev(upper_bound(v.begin(), v.end(), v[i] + b)) - v.begin();
    if (l > r) continue;
    uf.unite(i, l);
    w[l]++;
    w[r]--;
  }
  for (int i = 1; i < n; i++) w[i] += w[i - 1];
  for (int i = 0; i < n - 1; i++) if (w[i] > 0) uf.unite(i, i + 1);
  for (int i = 0; i < n; i++) {
    cout << uf.size(i) << '\n';
  }
  return 0;
}
0