結果

問題 No.1170 Never Want to Walk
ユーザー hayatenhayaten
提出日時 2020-08-15 15:35:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 372 ms / 2,000 ms
コード長 1,533 bytes
コンパイル時間 2,187 ms
コンパイル使用メモリ 197,964 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-04-19 01:14:20
合計ジャッジ時間 8,537 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 361 ms
5,760 KB
testcase_28 AC 355 ms
5,504 KB
testcase_29 AC 358 ms
5,760 KB
testcase_30 AC 356 ms
5,632 KB
testcase_31 AC 343 ms
5,632 KB
testcase_32 AC 351 ms
5,504 KB
testcase_33 AC 354 ms
5,504 KB
testcase_34 AC 360 ms
5,632 KB
testcase_35 AC 356 ms
5,632 KB
testcase_36 AC 350 ms
5,632 KB
testcase_37 AC 349 ms
5,760 KB
testcase_38 AC 372 ms
5,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

struct UnionFind {
  vector<int> par; //par[i]:iの親の番号

  //最初は全てが根であるとする。-1のときに根である。
  UnionFind(int N) : par(N, -1){}

  // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
  int root(int x) {
    if(par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }
  // データxが根かどうか
  bool cond_root(int x){
    if(par[x] < 0) return true;
    else return false;
  }
  //xとyが同じ集合に属するか
  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if(x == y) return false;
    if(par[x] > par[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  int size(int x) {
    return -par[root(x)];
  }
};

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> x(n);
  vector<int> imos(n);
  rep(i, n) cin >> x[i];
  UnionFind uf(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.merge(i, l);
    imos[l]++;
    imos[r]--;
  }
  rep(i, n - 1) imos[i + 1] += imos[i];
  rep(i, n - 1) {
    if(imos[i] > 0)uf.merge(i, i+1);
  }
  rep(i, n) {
    cout << uf.size(i) << endl;
  }
}
0