結果

問題 No.1170 Never Want to Walk
ユーザー auauaauaua
提出日時 2020-08-15 14:15:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 1,645 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 167,844 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-04-19 01:09:21
合計ジャッジ時間 5,301 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,376 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 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 128 ms
12,416 KB
testcase_28 AC 128 ms
12,160 KB
testcase_29 AC 131 ms
12,544 KB
testcase_30 AC 129 ms
12,416 KB
testcase_31 AC 128 ms
12,160 KB
testcase_32 AC 124 ms
12,288 KB
testcase_33 AC 125 ms
12,160 KB
testcase_34 AC 126 ms
12,416 KB
testcase_35 AC 121 ms
12,544 KB
testcase_36 AC 114 ms
12,288 KB
testcase_37 AC 121 ms
12,288 KB
testcase_38 AC 126 ms
12,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=2e5+3;
const int MAX=1000010;

int siz[200010];
int par[200010];
int depth[200010];
void init(int n){
  for(int i=0;i<=n;i++){
      par[i]=i;
      depth[i]=0;
  }
  rep(i,n+1){
      siz[i]=1;
  }
}
int root(int x){
  return par[x]==x?x:par[x]=root(par[x]);
}
bool same(int x,int y){
  return root(x)==root(y);
}
void unite(int x,int y){
  x=root(x);
  y=root(y);
  ll sx=siz[x];
  ll sy=siz[y];
  if(x==y)return;
  if(depth[x]<depth[y]){
      par[x]=y;
  }else{
      par[y]=x;
      if(depth[x]==depth[y])depth[x]++;
  }
  siz[root(x)]=sx+sy;
}
ll a,b;
signed main(){
    ll n;cin>>n>>a>>b;
    vector<ll>x(n);
    vector<ll>c(n);
    init(n);
    rep(i,n)cin>>x[i];
    x.pb(inf);
    rep(i,n){
        ll l=lower_bound(all(x),x[i]+a)-x.begin();
        ll r=upper_bound(all(x),x[i]+b)-x.begin();
        if(r==l)continue;
        if(l<n)unite(l,i);
        r--;
        r=max(r,l);
        c[l]++;
        if(r>=0&&r<n){
            c[r]--;
        }
    }
    rep(i,n-1){
        c[i+1]+=c[i];
        if(c[i]){
            unite(i,i+1);
        }
    }
    rep(i,n){
        cout<<siz[root(i)]<<endl;
    }
}
0