結果

問題 No.1170 Never Want to Walk
ユーザー 👑 NachiaNachia
提出日時 2020-10-07 16:20:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 339 ms / 2,000 ms
コード長 1,011 bytes
コンパイル時間 1,581 ms
コンパイル使用メモリ 169,588 KB
実行使用メモリ 7,116 KB
最終ジャッジ日時 2023-09-27 09:18:12
合計ジャッジ時間 10,270 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 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,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 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,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 3 ms
4,384 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 319 ms
6,684 KB
testcase_28 AC 330 ms
6,676 KB
testcase_29 AC 339 ms
7,116 KB
testcase_30 AC 333 ms
6,736 KB
testcase_31 AC 324 ms
6,676 KB
testcase_32 AC 316 ms
7,036 KB
testcase_33 AC 321 ms
7,000 KB
testcase_34 AC 327 ms
6,984 KB
testcase_35 AC 325 ms
7,052 KB
testcase_36 AC 332 ms
7,064 KB
testcase_37 AC 311 ms
6,684 KB
testcase_38 AC 329 ms
7,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

struct dsu{
 vector<int> V;
 vector<int> Z;
 void init(int n){
  V.resize(n);
  Z.resize(n);
  rep(i,n) V[i]=i;
  rep(i,n) Z[i]=1;
 }
 int root(int a){
  if(V[a]==a) return a;
  return V[a] = root(V[a]);
 }
 void unite(int a,int b){
  a=root(a); b=root(b);
  if(a==b) return;
  V[a]=b; Z[b]+=Z[a];
 }
 int size(int a){ return Z[root(a)]; }
} G;

int N;
LL A,B;
LL X[200001];
int to[200000];

int lower_bound_X(LL x){
 int l,r; l=0; r=N+1;
 while(l+1<r){
  int m=(l+r)/2;
  if(X[m-1]<x) l=m; else r=m;
 }
 return l;
}

int main(){
 cin>>N>>A>>B;
 rep(i,N) cin>>X[i];
 rep(i,N) to[i]=i;

 G.init(N);
 rep(i,N){
  int l=lower_bound_X(X[i]+A);
  int r=lower_bound_X(X[i]+B+1);
  if(l==N) continue;
  if(l!=r){
   to[l]=r-1;
   G.unite(i,l);
  }
 }

 rep(i,N-1) to[i+1]=max(to[i+1],to[i]);
 rep(i,N-1) if(to[i]!=i) G.unite(i,i+1);

 rep(i,N) cout<<G.size(i)<<endl;

 return 0;
}
0