結果
| 問題 | No.1170 Never Want to Walk |
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2020-10-07 16:20:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 372 ms / 2,000 ms |
| コード長 | 1,011 bytes |
| コンパイル時間 | 1,986 ms |
| コンパイル使用メモリ | 171,484 KB |
| 実行使用メモリ | 7,296 KB |
| 最終ジャッジ日時 | 2024-07-20 03:26:29 |
| 合計ジャッジ時間 | 9,678 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 37 |
ソースコード
#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;
}
Nachia