結果

問題 No.1170 Never Want to Walk
ユーザー optopt
提出日時 2020-05-19 18:39:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 1,024 bytes
コンパイル時間 3,437 ms
コンパイル使用メモリ 202,840 KB
実行使用メモリ 5,608 KB
最終ジャッジ日時 2023-09-16 08:41:33
合計ジャッジ時間 6,169 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 117 ms
5,608 KB
testcase_28 AC 115 ms
5,240 KB
testcase_29 AC 119 ms
5,340 KB
testcase_30 AC 117 ms
5,488 KB
testcase_31 AC 115 ms
5,456 KB
testcase_32 AC 112 ms
5,344 KB
testcase_33 AC 114 ms
5,144 KB
testcase_34 AC 114 ms
5,348 KB
testcase_35 AC 113 ms
5,340 KB
testcase_36 AC 110 ms
5,084 KB
testcase_37 AC 111 ms
5,600 KB
testcase_38 AC 116 ms
5,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using V = vector<int>;
#define rep(i, n) for(int i=0; i<int(n); ++i)
#define all(a) a.begin(), a.end()

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};


int main() {
  int n, a, b; cin >> n >> a >> b;
  V x(n);
  rep(i, n) cin >> x[i];

  UnionFind uf(n);
  V y(n);

  rep(i, n) {
    int l = lower_bound(all(x), x[i]+a) - x.begin();
    int r = upper_bound(all(x), x[i]+b) - x.begin() - 1;
    if (l > r) continue;
    uf.unite(i, l);
    ++y[l];
    --y[r];
  }
  rep(i, n-1) y[i+1] += y[i];
  rep(i, n-1) if (y[i] > 0) uf.unite(i, i+1);

  rep(i, n) cout << uf.size(i) << "\n";
  return 0;
}
0