結果

問題 No.1170 Never Want to Walk
ユーザー optopt
提出日時 2020-05-19 18:21:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,000 bytes
コンパイル時間 1,937 ms
コンパイル使用メモリ 203,564 KB
実行使用メモリ 5,656 KB
最終ジャッジ日時 2023-09-16 08:41:16
合計ジャッジ時間 6,436 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
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
4,380 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 109 ms
5,084 KB
testcase_34 WA -
testcase_35 AC 110 ms
5,656 KB
testcase_36 AC 107 ms
5,132 KB
testcase_37 AC 107 ms
5,472 KB
testcase_38 AC 112 ms
5,396 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 s(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;
    uf.unite(i, l);
    ++s[l];
    --s[r];
  }
  rep(i, n-1) s[i+1] += s[i];
  rep(i, n-1) if (s[i] > 0) uf.unite(i, i+1);

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