結果

問題 No.1170 Never Want to Walk
ユーザー CleyLCleyL
提出日時 2022-09-21 12:57:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 1,349 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 82,416 KB
実行使用メモリ 7,076 KB
最終ジャッジ日時 2023-08-23 19:54:30
合計ジャッジ時間 8,880 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,504 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,380 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 4 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 4 ms
4,376 KB
testcase_27 AC 350 ms
6,800 KB
testcase_28 AC 350 ms
6,712 KB
testcase_29 AC 356 ms
6,920 KB
testcase_30 AC 345 ms
6,780 KB
testcase_31 AC 347 ms
6,708 KB
testcase_32 AC 342 ms
6,652 KB
testcase_33 AC 345 ms
6,820 KB
testcase_34 AC 349 ms
7,048 KB
testcase_35 AC 349 ms
7,076 KB
testcase_36 AC 340 ms
6,784 KB
testcase_37 AC 343 ms
6,788 KB
testcase_38 AC 357 ms
6,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct UnionFind {
  int n;
  vector<int> par;
  vector<int> size_;
  UnionFind(int n_) : n(n_), par((size_t)n_), size_((size_t)n_,1){
    for(int i = 0; n > i; i++)par[i] = i;
  }

  int root(int x){
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
  }

  void unite(int a,int b){
    int ra = root(a);
    int rb = root(b);
    if(ra==rb)return;
    if(size(ra) > size(rb)) swap(ra,rb);
    par[ra] = rb;
    size_[rb] += size_[ra];
  }

  bool same(int a, int b){
    return root(a) == root(b);
  }

  int size(int a){
    return size_[root(a)];
  }
  void debug(){
    for(int i = 0; n > i; i++){
      cout << size_[root(i)] << " ";
    }
    cout << endl;

    return;
  }
};
int main(){
  int n,a,b;cin>>n>>a>>b;
  vector<int> A(n);
  vector<pair<int,int>> B(n+1);
  UnionFind C(n);
  for(int i = 0; n > i; i++)cin>>A[i];
  for(int i = 0; n > i; i++){
    auto x = lower_bound(A.begin(),A.end(),A[i]+a)-A.begin();
    auto y = upper_bound(A.begin(),A.end(),A[i]+b)-A.begin();
    if(x<y){
      B[x].first++;
      B[y].second++;
      C.unite(i,x);
    }

  }
  int nw = 0;
  for(int i = 0; n > i; i++){
    nw -= B[i].second;
    if(nw)C.unite(i-1,i);
    nw += B[i].first;
  }
  for(int i = 0; n > i; i++){
    cout << C.size(i) << endl;
  }
}

0