結果
| 問題 |
No.1170 Never Want to Walk
|
| コンテスト | |
| ユーザー |
Manuel1024
|
| 提出日時 | 2021-04-28 23:47:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,274 ms / 2,000 ms |
| コード長 | 1,700 bytes |
| コンパイル時間 | 756 ms |
| コンパイル使用メモリ | 76,600 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-07 23:07:51 |
| 合計ジャッジ時間 | 18,301 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 37 |
ソースコード
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
struct UnionFind{
vector<int> parent;
UnionFind(int n){
parent = vector<int>(n, -1);
}
int root(int x){
if(parent[x] < 0) return x;
else return parent[x] = root(parent[x]);
}
bool same(int x, int y){
x = root(x);
y = root(y);
return x == y;
}
int count(int x){
x = root(x);
return -parent[x];
}
void unite(int x, int y){
x = root(x);
y = root(y);
if(x == y) return;
if(count(x) < count(y)){
int t = x; x = y; y = t;
}
parent[x] += parent[y];
parent[y] = x;
}
};
int main(){
int n, a, b;
cin >> n >> a >> b;
vector<int> x(n);
for(auto &p: x) cin >> p;
UnionFind data(n);
int plind = -1, prind = -1;
for(int i = 0; i < n; i++){
int lind = n;
int lwa = i;
while(lind-lwa > 1){
int mid = (lind+lwa)/2;
if(abs(x[mid]-x[i]) >= a) lind = mid;
else lwa = mid;
}
int rind = i;
int rwa = n;
while(rwa-rind > 1){
int mid = (rind+rwa)/2;
if(abs(x[mid]-x[i]) <= b) rind = mid;
else rwa = mid;
}
//cerr << lind << " " << rind << " -> ";
if(prind >= lind){
lind = prind;
prind = rind;
}else{
plind = lind;
prind = rind;
}
cerr << lind << " " << rind << endl;
for(int j = lind; j <= rind; j++) data.unite(i, j);
}
for(int i = 0; i < n; i++) cout << data.count(i) << endl;
return 0;
}
Manuel1024