結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
merom686
|
| 提出日時 | 2020-08-14 21:53:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 55 ms / 2,000 ms |
| コード長 | 1,205 bytes |
| コンパイル時間 | 968 ms |
| コンパイル使用メモリ | 92,852 KB |
| 最終ジャッジ日時 | 2025-01-12 23:42:45 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 37 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
struct UnionFind {
UnionFind(int n) : p(n, -1) {}
int root(int u) {
return p[u] < 0 ? u : p[u] = root(p[u]);
}
int size(int u) {
return -p[root(u)];
}
bool same(int u, int v) {
return root(u) == root(v);
}
void unite(int u, int v) {
u = root(u);
v = root(v);
if (u == v) return;
if (p[u] > p[v]) swap(u, v);
p[u] += p[v];
p[v] = u;
}
vector<int> p;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, a, b;
cin >> n >> a >> b;
vector<int> x(n);
for (int i = 0; i < n; i++) {
cin >> x[i];
}
UnionFind uf(n);
int i0, i1 = 0;
for (int i = 0; i < n; i++) {
i0 = i1;
while (i1 < n && x[i1] <= x[i] + b) i1++;
for (int j = i1 - 1; j >= max(i0 - 1, 0); j--) {
if (x[j] < x[i] + a) break;
uf.unite(i, j);
}
}
for (int i = 0; i < n; i++) {
cout << uf.size(i) << '\n';
}
return 0;
}
merom686