結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
Dente
|
| 提出日時 | 2020-08-14 22:23:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,451 bytes |
| コンパイル時間 | 2,248 ms |
| コンパイル使用メモリ | 194,640 KB |
| 最終ジャッジ日時 | 2025-01-13 00:09:11 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 32 TLE * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
#define MAX 200000
struct UnionFind {
vector<int> par, siz;
UnionFind(int n) : par(n), siz(n, 1) {
iota(par.begin(), par.end(), 0);
}
int root(int x) {
if (par[x] == x)
return x;
else
return par[x] = root(par[x]);
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y) return;
if (siz[x] < siz[y]) swap(x, y);
siz[x] += siz[y];
par[y] = x;
}
bool same(int x, int y) {
return root(x) == root(y);
}
int size(int x) {
return siz[root(x)];
}
};
int n;
ll a, b;
ll x[MAX];
bool visited[MAX];
UnionFind uf(MAX);
void dfs(int cur) {
if (visited[cur]) return;
visited[cur] = true;
int l = lower_bound(x, x + n, x[cur] + a) - x;
int r = upper_bound(x, x + n, x[cur] + b) - x;
if (l < n) dfs(l);
if (r - 1 > l) dfs(r - 1);
for (int i = l; i < r; i++) {
visited[i] = true;
uf.unite(cur, i);
}
}
signed main() {
cin >> n >> a >> b;
rep(i, n) {
cin >> x[i];
}
rep(i, n) {
dfs(i);
}
rep(i, n) {
cout << uf.size(i) << endl;
}
return 0;
}
Dente