結果

問題 No.1170 Never Want to Walk
ユーザー tko919tko919
提出日時 2020-08-14 23:27:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 379 ms / 2,000 ms
コード長 1,340 bytes
コンパイル時間 2,017 ms
コンパイル使用メモリ 167,568 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-04-18 23:15:10
合計ジャッジ時間 7,709 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 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 1 ms
5,376 KB
testcase_07 AC 1 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 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 353 ms
5,504 KB
testcase_28 AC 351 ms
5,504 KB
testcase_29 AC 372 ms
5,504 KB
testcase_30 AC 369 ms
5,504 KB
testcase_31 AC 360 ms
5,504 KB
testcase_32 AC 353 ms
5,760 KB
testcase_33 AC 343 ms
5,632 KB
testcase_34 AC 366 ms
5,632 KB
testcase_35 AC 354 ms
5,632 KB
testcase_36 AC 348 ms
5,632 KB
testcase_37 AC 344 ms
5,632 KB
testcase_38 AC 379 ms
5,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

struct UnionFind{
   vector<int> par; int n;
   UnionFind(){}
   UnionFind(int _n):par(_n,-1),n(_n){}
   int root(int x){return par[x]<0?x:par[x]=root(par[x]);}
   bool same(int x,int y){return root(x)==root(y);}
   int size(int x){return -par[root(x)];}
   bool unite(int x,int y){
      x=root(x),y=root(y); if(x==y)return false;
      if(size(x)>size(y))swap(x,y);
      par[y]+=par[x]; par[x]=y; n--; return true;
   }
};

int main(){
   int n,x,y; cin>>n>>x>>y;
   vector<int> a(n);
   rep(i,0,n)cin>>a[i];
   vector<int> rui(n,0); UnionFind uni(n);
   rep(i,0,n){
      int lb=lower_bound(ALL(a),a[i]+x)-a.begin();
      int rb=upper_bound(ALL(a),a[i]+y)-a.begin()-1;
      if(lb>rb)continue;
      uni.unite(i,lb);
      rui[lb]++; rui[rb]--;
   }
   rep(i,0,n-1)rui[i+1]+=rui[i];
   rep(i,0,n-1)if(rui[i])uni.unite(i,i+1);
   rep(i,0,n)cout<<uni.size(i)<<endl;
   return 0;
}
0