結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-14 21:42:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 410 ms / 2,000 ms |
| コード長 | 2,342 bytes |
| コンパイル時間 | 2,208 ms |
| コンパイル使用メモリ | 196,392 KB |
| 最終ジャッジ日時 | 2025-01-12 23:28:42 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 37 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};
struct Union_Find_Tree{
vector<int> par, rank, num;
Union_Find_Tree(int N){
par.assign(N, -1);
rank.assign(N, 0);
num.assign(N, 1);
}
int root(int x){
if(par[x] < 0 || par[x] == x) return x;
return par[x] = root(par[x]);
}
bool unite(int x, int y){
x = root(x), y = root(y);
if(x == y) return false;
if(rank[x] < rank[y]) swap(x, y);
if(rank[x] == rank[y]) rank[x]++;
par[y] = x, num[x] += num[y];
return true;
}
int size(int x) {return num[root(x)];}
bool same(int x, int y){
return root(x) == root(y);
}
void clear(){
fill(par.begin(), par.end(), -1);
fill(rank.begin(), rank.end(), 0);
fill(num.begin(), num.end(), 1);
}
};
int main(){
int N, A, B;
cin >> N >> A >> B;
int x[N];
rep(i, N) cin >> x[i];
int pos1 = 0, pos2 = 0;
Union_Find_Tree uf(N);
rep(i, N){
int nxt1 = pos1, nxt2 = pos2;
while(nxt1 < N && x[nxt1]-x[i] < A) nxt1++;
while(nxt2 < N && x[nxt2]-x[i] <= B) nxt2++;
if(nxt1 == nxt2){
pos1 = nxt1, pos2 = nxt2;
continue;
}
if(nxt1 < N) uf.unite(i, nxt1);
if(nxt1 >= pos2){
rep2(i, nxt1, nxt2-2) uf.unite(i, i+1);
}
else{
rep2(i, pos2-1, nxt2-2) uf.unite(i, i+1);
}
pos1 = nxt1, pos2 = nxt2;
}
rep(i, N) cout << uf.size(i) << endl;
}