結果

問題 No.1170 Never Want to Walk
ユーザー ScottShelbyScottShelby
提出日時 2020-10-15 15:37:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 1,174 bytes
コンパイル時間 2,139 ms
コンパイル使用メモリ 170,916 KB
実行使用メモリ 6,292 KB
最終ジャッジ日時 2023-09-28 01:09:58
合計ジャッジ時間 10,471 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 2 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,376 KB
testcase_25 AC 3 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 310 ms
5,976 KB
testcase_28 AC 297 ms
5,880 KB
testcase_29 AC 316 ms
6,292 KB
testcase_30 AC 311 ms
6,216 KB
testcase_31 AC 304 ms
6,132 KB
testcase_32 AC 305 ms
5,984 KB
testcase_33 AC 308 ms
6,024 KB
testcase_34 AC 315 ms
6,160 KB
testcase_35 AC 305 ms
6,140 KB
testcase_36 AC 306 ms
6,024 KB
testcase_37 AC 310 ms
6,028 KB
testcase_38 AC 319 ms
6,184 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<ll> x(n);
  rep(i, n) cin >> x[i];

  vector<int> sum(n + 1);
  UnionFind uf(n);

  rep(i, n) {
    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() - 1;
    if (r < l) continue;
    uf.unite(i, l);
    sum[l]++;
    sum[r]--;
  }

  rep(i, n) sum[i + 1] += sum[i];
  rep(i, n) if (sum[i] > 0) uf.unite(i, i + 1);
  rep(i, n) cout << uf.size(i) << endl;
}
0