結果
問題 |
No.1170 Never Want to Walk
|
ユーザー |
![]() |
提出日時 | 2023-08-02 22:53:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 123 ms / 2,000 ms |
コード長 | 978 bytes |
コンパイル時間 | 1,859 ms |
コンパイル使用メモリ | 200,536 KB |
最終ジャッジ日時 | 2025-02-15 21:30:22 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 37 |
ソースコード
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; using pii = pair<int, int>; int n, a, b, x[N], ans[N]; int q[N], h, t; set<pii> s; void bfs(int st) { h = t = 0; q[t ++] = st; s.erase({x[st], st}); while(h < t) { int u = q[h ++]; int lt = t; for(auto it = s.lower_bound({x[u] - b, -1}); it != s.end() && it->first <= x[u] - a; it ++) q[t ++] = it->second; for(auto it = s.lower_bound({x[u] + a, -1}); it != s.end() && it->first <= x[u] + b; it ++) q[t ++] = it->second; while(lt < t) s.erase({x[q[lt]], q[lt ++]}); } for(int i = 0; i < t; i ++) ans[q[i]] = t; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> a >> b; for(int i = 1; i <= n; i ++) { cin >> x[i]; s.insert({x[i], i}); } for(int i = 1; i <= n; i ++) { if(!ans[i]) bfs(i); cout << ans[i] << "\n"; } }