結果

問題 No.1170 Never Want to Walk
ユーザー ScottShelbyScottShelby
提出日時 2020-10-30 23:44:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 358 ms / 2,000 ms
コード長 1,216 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 169,776 KB
実行使用メモリ 5,552 KB
最終ジャッジ日時 2023-09-29 08:45:14
合計ジャッジ時間 9,835 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 349 ms
5,328 KB
testcase_28 AC 347 ms
5,280 KB
testcase_29 AC 358 ms
5,324 KB
testcase_30 AC 352 ms
5,432 KB
testcase_31 AC 350 ms
5,148 KB
testcase_32 AC 340 ms
5,496 KB
testcase_33 AC 349 ms
5,284 KB
testcase_34 AC 350 ms
5,428 KB
testcase_35 AC 354 ms
5,440 KB
testcase_36 AC 340 ms
5,232 KB
testcase_37 AC 347 ms
5,552 KB
testcase_38 AC 355 ms
5,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

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;
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  UnionFind uf(n);
  vector<int> sums(n);

  rep(i, n) {
    auto s = lower_bound(x.begin(), x.end(), x[i] + a) - x.begin();
    auto e = upper_bound(x.begin(), x.end(), x[i] + b) - x.begin() - 1;
    if (s > e) continue;
    uf.unite(i, s);
    sums[s]++;
    sums[e]--;
  }

  rep(i, n - 1) sums[i + 1] += sums[i];
  rep(i, n - 1) if (sums[i] > 0) uf.unite(i, i + 1);
  rep(i, n) {
    int ans = uf.size(i);
    cout << ans << endl;
  }
}
0