結果

問題 No.1170 Never Want to Walk
ユーザー iqueue02iqueue02
提出日時 2020-08-15 12:14:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 370 ms / 2,000 ms
コード長 1,404 bytes
コンパイル時間 2,079 ms
コンパイル使用メモリ 198,840 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 00:34:57
合計ジャッジ時間 8,240 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9;

struct UnionFind{
  vector<int> data;
  int __size;
  UnionFind(int sz) {
  data.assign(sz, -1);
  __size = sz;
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);//親は負でサイズを保存
    __size--;
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  bool same(int x, int y){
    return find(x) == find(y);
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }

  int union_count() {
    return (__size);
  }
};
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> x(n);
  rep(i,n) cin >> x[i];

  UnionFind uf(n);
  vector<int> imos(n, 0);

  for (int i = 0; i < n; i++) {
    int l = lower_bound(x.begin(), x.end(), x[i] + a) - x.begin();
    int r = upper_bound(x.begin(), x.end(), x[i] + b) - x.begin();
    r--;
    if (l > r) continue;
    uf.unite(i, l);
    imos[l]++;
    imos[r]--;
  }

  for (int i = 0; i < n; i++) imos[i + 1] += imos[i];
  for (int i = 0; i < n; i++) if (imos[i] > 0) uf.unite(i, i + 1);

  for (int i = 0; i < n; i++) cout << uf.size(i) << endl;  
  return 0;
}
0