結果

問題 No.1170 Never Want to Walk
ユーザー ytqm3ytqm3
提出日時 2021-06-22 20:16:34
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 363 ms / 2,000 ms
コード長 2,951 bytes
コンパイル時間 2,283 ms
コンパイル使用メモリ 203,908 KB
実行使用メモリ 7,200 KB
最終ジャッジ日時 2023-09-05 21:09:06
合計ジャッジ時間 10,821 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 3 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,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 354 ms
6,692 KB
testcase_28 AC 345 ms
6,792 KB
testcase_29 AC 363 ms
7,136 KB
testcase_30 AC 362 ms
7,200 KB
testcase_31 AC 343 ms
6,812 KB
testcase_32 AC 349 ms
7,092 KB
testcase_33 AC 348 ms
7,136 KB
testcase_34 AC 354 ms
6,964 KB
testcase_35 AC 352 ms
6,916 KB
testcase_36 AC 345 ms
6,924 KB
testcase_37 AC 347 ms
6,820 KB
testcase_38 AC 359 ms
6,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
typedef uint64_t u64;
typedef int64_t i64;
typedef long double f128;
using namespace std;

template<typename T>
void scan(T& n){
  cin>>n;
}

void scan(){}

template<typename T,class... Args>
void scan(T& n,Args&... args){
  scan(n);
  scan(args...);
}

template<typename T>
void scanall(T start,T end){
  for(;start!=end;++start){
    scan(*start);
  }
}

template<typename T>
void print(T n){
  cout<<n;
}

void print(){}

template<typename T,class... Args>
void print(T n,Args... args){
  print(n);
  print(args...);
}

template<typename T>
void println(T n){
  print(n);
  cout<<endl;
}

template<typename T,class... Args>
void println(T n,Args... args){
  print(n,' ');
  println(args...);
}

template<typename T>
void printall(T start,T end){
  if(start!=end){
    print(*start);
    for(++start;start!=end;++start){
      print(' ',*start);
    }
  }
  cout<<endl;
}

template<typename T>
void chmax(T& n,T m){
  n=max(n,m);
}

template<typename T>
void chmin(T& n,T m){
  n=min(n,m);
}

template<typename T,typename U>
T power(T a,U n){
  T res=1;
  while(n){
    res*=(n&1)?a:1;
    a*=a;
    n>>=1;
  }
  return res;
}

template<typename T>
struct combination{
  vector<T> fact;
  combination(const int Max=3000000):fact(Max+1,1){
    for(int i=2;i<=Max;++i){
      fact[i]=fact[i-1]*i;
    }
  }
  template<typename U>
  T nCk(U n,U k){
    if(n<k||n<0||k<0){
      return 0;
    }
    return fact[n]/fact[k]/fact[n-k];
  }
};

template<typename T>
struct unionfind{
  T Max;
  vector<T> par,siz;
  unionfind(T Max_):Max(Max_),par(Max_),siz(Max_,1){
    for(T i=0;i<Max;++i){
      par[i]=i;
    }
  }
  T root(T x){
    if(par[x]==x){
      return x;
    }
    else{
      return par[x]=root(par[x]);
    }
  }
  vector<T> parset(){
    vector<T> res(0);
    for(T i=0;i<Max;++i){
      if(root(i)==i){
        res.emplace_back(i);
      }
    }
    return res;
  }
  void unite(T x,T y){
    x=root(x);
    y=root(y);
    if(x>y){
      par[y]=x;
      siz[x]+=siz[y];
    }
    if(x<y){
      par[x]=y;
      siz[y]+=siz[x];
    }
  }
  T size(T x){
    return siz[root(x)];
  }
};

void solve();

int main(){
  cout<<fixed<<setprecision(15);
  bool is_multicase=false;
  int T=1;
  if(is_multicase){
    scan(T);
  }
  for(int i=0;i<T;++i){
    solve();
  }
  return 0;
}

void solve(){
  int N,A,B;
  scan(N,A,B);
  vector<int> x(N);
  scanall(x.begin(),x.end());
  vector<int> table(N);
  unionfind<int> UF(N);
  for(int i=0;i<N;++i){
    int Left=lower_bound(x.begin(),x.end(),x[i]+A)-x.begin();
    int Right=upper_bound(x.begin(),x.end(),x[i]+B)-x.begin();
    if(Left==Right){
      continue;
    }
    table[Left]++;
    table[Right-1]--;
    UF.unite(i,Left);
  }
  vector<int> imos(N-1);
  imos[0]=table[0];
  for(int i=1;i<N-1;++i){
    imos[i]=imos[i-1]+table[i];
  }
  for(int i=0;i<N-1;++i){
    if(imos[i]!=0){
      UF.unite(i,i+1);
    }
  }
  for(int i=0;i<N;++i){
    println(UF.size(i));
  }
}
0