結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-14 23:42:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 362 ms / 2,000 ms |
| コード長 | 1,578 bytes |
| コンパイル時間 | 1,784 ms |
| コンパイル使用メモリ | 175,076 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-10 16:53:46 |
| 合計ジャッジ時間 | 8,120 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 37 |
ソースコード
/**
* author: boutarou
* created: 14.08.2020 22:28:10
**/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
using ll = long long;
using P = pair<int, int>;
class UnionFind {
private:
vector<int>par;
public:
UnionFind(int n) {
for (int i = 0; i < n; i++) par.push_back(-1);
}
int root(int x) {
if (par[x] < 0) return x;
else return par[x] = root(par[x]);
}
bool same(int x, int y) { return root(x) == root(y);}
void unite(int x, int y) {
x = root(x), y = root(y);
if (x == y) return;
if (par[x] > par[y]) swap(x, y);
par[x] += par[y];
par[y] = x;
return;
}
int size(int x) { return -par[root(x)];}
};
int main() {
ll n, a, b;
cin >> n >> a >> b;
vector<ll> x(n);
rep(i, n) cin >> x[i];
UnionFind uf(n);
vector<int> imos(n, 0);
rep(i, n) {
int before = lower_bound(x.begin(), x.end(), x[i] + a) - x.begin();
int after = upper_bound(x.begin(), x.end(), x[i] + b) - x.begin() - 1;
if (before <= after && (0 <= before && before <= n - 1) && (0 <= after && after <= n - 1)) {
uf.unite(i, before);
imos[before]++, imos[after]--;
}
}
for (int i = 1; i <= n - 2; i++) {
imos[i] += imos[i - 1];
}
rep(i, n - 1) {
if (imos[i] > 0) uf.unite(i, i + 1);
}
rep(i, n) {
cout << uf.size(i) << endl;
}
return 0;
}