結果
問題 | No.1170 Never Want to Walk |
ユーザー |
![]() |
提出日時 | 2020-08-14 21:35:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 419 ms / 2,000 ms |
コード長 | 2,105 bytes |
コンパイル時間 | 1,388 ms |
コンパイル使用メモリ | 124,800 KB |
最終ジャッジ日時 | 2025-01-12 23:24:22 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 37 |
ソースコード
#include <cstdio> #include <iostream> #include <string> #include <vector> #include <sstream> #include <map> #include <set> #include <queue> #include <algorithm> #include <cmath> #include <cstring> #include <typeinfo> #include <numeric> #include <functional> #include <unordered_map> #include <bitset> #include <stack> #include <assert.h> #include <unordered_set> #include <random> using namespace std; using ll = long long; using ull = unsigned long long; const ll INF = 1e18; const ll MOD = 1e9 + 7; #define REP(i, n) for(ll i = 0; i < n; i++) class Unionfind { private: vector<int> par; vector<int> rank; vector<int> counter; public: Unionfind(int n) : rank(n), counter(n, 1){ for(int i = 0; i < n; i++){ par.push_back(i); } } int find(int x){ if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(int x, int y){ x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) { counter[y] += counter[x]; counter[x] = counter[y]; par[x] = y; } else { counter[y] += counter[x]; counter[x] = counter[y]; par[y] = x; if (rank[x] == rank[y]) { rank[x]++; } } } bool same(int x, int y){ return find(x) == find(y); } ll count(int x){ return counter[find(x)]; } }; int main(){ ll n, a, b; cin >> n >> a >> b; vector<ll> x(n); REP(i, n){ cin >> x[i]; } Unionfind uni(n); REP(i, n){ ll itr1 = lower_bound(x.begin() + i, x.end(), x[i] + a) - x.begin(); ll itr2 = --lower_bound(x.begin() + i, x.end(), x[i] + b + 1) - x.begin(); while(itr1 < n && itr2 >= 0 && x[itr1] <= x[itr2] && !uni.same(i, itr2)){ uni.unite(i, itr2); itr2--; } } REP(i, n){ cout << uni.count(i) << endl; } }