結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
poohbear
|
| 提出日時 | 2020-08-15 07:57:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 401 ms / 2,000 ms |
| コード長 | 1,913 bytes |
| コンパイル時間 | 2,337 ms |
| コンパイル使用メモリ | 198,300 KB |
| 最終ジャッジ日時 | 2025-01-13 01:08:35 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 37 |
ソースコード
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
using Graph = vector<vector<ll> >;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
//UnionFind
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int n) : par(n, -1) { }
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] < 0) return x;
return par[x] = root(par[x]);
}
bool merge(int x, int y) {//xの木とyの木を結合する
x = root(x); y = root(y);
if (x == y) return false;
if (par[x] > par[y]) swap(x, y); // merge technique
par[x] += par[y];
par[y] = x;
return true;
}
int size(int x) {//sizeの取得
return -par[root(x)];
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
};
//input
ll n,a,b;
vector<ll>x;
int main(){
cin >> n >> a >> b;
x.resize(n);
rep(i,n)cin>>x[i];
UnionFind u(n+1);
vector<ll>seg(n+1,0);
for(int i=n-1;i>=0;i--){
ll r = lower_bound(x.begin(),x.end(),x[i]+b+1)-x.begin();
ll l = lower_bound(x.begin(),x.end(),x[i]+a)-x.begin();
if(l==n)continue;
if(l==r)continue;
u.merge(i,l);
u.merge(i,r-1);
seg[l]++;
seg[r-1]--;
}
rep(i,n){
seg[i+1]+=seg[i];
}
rep(i,n){
if(seg[i])u.merge(i,i+1);
}
rep(i,n){
cout << u.size(i) << endl;
}
return 0;
}
poohbear