結果

問題 No.1170 Never Want to Walk
ユーザー chocono2230chocono2230
提出日時 2020-08-14 22:31:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 361 ms / 2,000 ms
コード長 1,387 bytes
コンパイル時間 1,762 ms
コンパイル使用メモリ 168,064 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 22:21:44
合計ジャッジ時間 8,053 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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 4 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 4 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 349 ms
5,376 KB
testcase_28 AC 346 ms
5,376 KB
testcase_29 AC 356 ms
5,376 KB
testcase_30 AC 361 ms
5,376 KB
testcase_31 AC 350 ms
5,376 KB
testcase_32 AC 341 ms
5,376 KB
testcase_33 AC 343 ms
5,376 KB
testcase_34 AC 351 ms
5,376 KB
testcase_35 AC 345 ms
5,376 KB
testcase_36 AC 335 ms
5,376 KB
testcase_37 AC 341 ms
5,376 KB
testcase_38 AC 356 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

struct UnionFind{
  vector<int> d;
  UnionFind(int n) : d(n, -1){}
  int find(int x){
    if(d.at(x) < 0) return x;
    return d.at(x) = find(d.at(x));
  }
  bool unite(int x, int y){
    x = find(x); y = find(y);
    if(x == y) return false;
    if(d.at(x) > d.at(y)) swap(x, y);
    d.at(x) += d.at(y);
    d.at(y)= x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d.at(find(x)); }
};

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> x(n);
  rep(i, n) cin >> x.at(i);
  UnionFind uf(n);
  int mxl = 0;
  rep(i, n){
    int l = x.at(i)+a, r = x.at(i)+b;
    auto itr = lower_bound(ALL(x), max(l, mxl));
    while(itr != x.end()){
      if(*itr > r) break;
      int index = itr - x.begin();
      uf.unite(i, index);
      mxl = *itr;
      itr++;
    }
  }

  rep(i, n){
    cout << uf.size(i) << endl;
  }
  return 0;
}
0