結果
問題 | No.1170 Never Want to Walk |
ユーザー | fuppy_kyopro |
提出日時 | 2020-08-14 22:14:29 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 7,819 bytes |
コンパイル時間 | 2,821 ms |
コンパイル使用メモリ | 197,072 KB |
実行使用メモリ | 372,540 KB |
最終ジャッジ日時 | 2024-10-10 15:33:57 |
合計ジャッジ時間 | 17,451 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 6 ms
5,248 KB |
testcase_21 | WA | - |
testcase_22 | AC | 7 ms
5,248 KB |
testcase_23 | AC | 7 ms
5,248 KB |
testcase_24 | AC | 7 ms
5,248 KB |
testcase_25 | AC | 7 ms
5,248 KB |
testcase_26 | AC | 7 ms
5,248 KB |
testcase_27 | AC | 814 ms
157,172 KB |
testcase_28 | AC | 798 ms
153,900 KB |
testcase_29 | AC | 791 ms
150,632 KB |
testcase_30 | AC | 801 ms
154,248 KB |
testcase_31 | AC | 806 ms
153,668 KB |
testcase_32 | AC | 1,283 ms
299,868 KB |
testcase_33 | AC | 1,342 ms
372,540 KB |
testcase_34 | AC | 1,262 ms
357,888 KB |
testcase_35 | AC | 1,152 ms
298,156 KB |
testcase_36 | AC | 1,194 ms
333,664 KB |
testcase_37 | AC | 1,304 ms
304,216 KB |
testcase_38 | AC | 1,151 ms
288,828 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define DEBUG(x) cerr<<#x<<": "<<x<<endl; #define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl; #define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;} typedef long long ll; // #define int ll #define vi vector<int> #define vl vector<ll> #define vii vector< vector<int> > #define vll vector< vector<ll> > #define vs vector<string> #define pii pair<int,int> #define pis pair<int,string> #define psi pair<string,int> #define pll pair<ll,ll> template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); } template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); } template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i<b;i++) #define in(x, a, b) (a <= x && x < b) #define all(c) c.begin(),c.end() template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl; // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 }; vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1}; // vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 }; #define fio() cin.tie(0); ios::sync_with_stdio(false); const ll MOD = 1000000007; // const ll MOD = 998244353; // #define mp make_pair //#define endl '\n' int nn; class UnionFind { public: int n; vi par; //�e vi ran; //�̐[�� vi num; //�v�f�� int g; // group�� UnionFind(){} UnionFind(int _n) { n = _n; g = n; par.resize(n); ran.resize(n); num.resize(n); for (int i = 0; i < n; i++) { par[i] = i; ran[i] = 0; if (i < nn) { num[i] = 1; } } } //�̍������߂� int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } //x��y�̑�����W���� void unite(int x, int y) { x = find(x); y = find(y); int numsum = num[x] + num[y]; if (x == y) { return; } if (ran[x]<ran[y]) { par[x] = y; } else { par[y] = x; if (ran[x] == ran[y]) { ran[x]++; } } num[x] = num[y] = numsum; g--; } //x��y�������W���ɑ����邩�ۂ� bool same(int x, int y) { return find(x) == find(y); } }; UnionFind uf; class RangeEdges { // https://twitter.com/noshi91/status/1193177214453338113 // https://codeforces.com/contest/786/submission/85182398 // https://atcoder.jp/contests/nikkei2019-2-qual/submissions/14711404 public: int n; // 問題で与えられた頂点数 int V; // 構築するグラフの頂点数 vector<vector<pll>> G; vector<bool> used; // 0 ~ n - 1: 各頂点 // n, n + 2, n + 4, ..., n + 2 * (K - 1): out側の各区間(図の上側) // n + 1, n + 3, ..., n + 2 * K - 1: in側の各区間(図の下側) // n + 2 * K ~ 辺を貼ることによって増えたスーパー頂点 RangeEdges(int n): n(n), V(n) { G.resize(9 * n); used.resize(9 * n, false); init(0, 0, n); } void init(int k, int l, int r) { if (r - l == 1) { G[n + 2 * k].push_back(pll(0, l)); G[l].push_back(pll(0, n + 2 * k + 1)); chmax(V, n + 2 * k + 2); return; } int lch = 2 * k + 1, rch = 2 * k + 2; G[n + 2 * k].push_back(pll(0, n + 2 * lch)); G[n + 2 * k].push_back(pll(0, n + 2 * rch)); G[n + 2 * lch + 1].push_back(pll(0, n + 2 * k + 1)); G[n + 2 * rch + 1].push_back(pll(0, n + 2 * k + 1)); init(lch, l, (l + r) / 2); init(rch, (l + r) / 2, r); } void get_ranges(int a, int b, int k, int l, int r, vector<int>& res) { if (r <= a || b <= l) { return; } if (a <= l && r <= b) { res.push_back(k); return; } else { get_ranges(a, b, k * 2 + 1, l, (l + r) / 2, res); get_ranges(a, b, k * 2 + 2, (l + r) / 2, r, res); return; } } // [lr1.first, lr1.second) -> [lr2.first, lr2.second)にcostの辺を貼る void add_edge(pii lr1, pii lr2, ll cost) { vector<int> in_ranges; get_ranges(lr1.first, lr1.second, 0, 0, n, in_ranges); rep (i, in_ranges.size()) in_ranges[i] = n + in_ranges[i] * 2 + 1; vector<int> out_ranges; get_ranges(lr2.first, lr2.second, 0, 0, n, out_ranges); rep (i, out_ranges.size()) out_ranges[i] = n + out_ranges[i] * 2; // DEBUG_VEC(in_ranges); // DEBUG_VEC(out_ranges); V += 2; while (G.size() < V) { G.push_back(vector<pll>()); used.push_back(false); } for (int u: in_ranges) { G[u].push_back(pll(0, V - 2)); } G[V - 2].push_back(pll(cost, V - 1)); for (int v: out_ranges) { G[V - 1].push_back(pll(0, v)); } } vl dijkstra(int s) { vl dist(V, INF); dist[s] = 0; priority_queue<pll, vector<pll>, greater<pll>> pq; pq.push(pll(0, s)); while (pq.size()) { pll temp = pq.top(); pq.pop(); int u = temp.second; ll cost = temp.first; if (dist[u] < cost) continue; rep (i, G[u].size()) { int v = G[u][i].second; ll ncost = cost + G[u][i].first; if (dist[v] > ncost) { dist[v] = ncost; pq.push(pll(ncost, v)); } } } dist.resize(n); return dist; } void dfs(int ori_u, int u) { used[u] = true; rep (i, G[u].size()) { int v = G[u][i].second; if (used[v]) continue; if (v < nn) { uf.unite(ori_u, v); } dfs(ori_u, v); } } }; signed main() { fio(); int n, a, b; cin >> n >> a >> b; nn = n; vi x(n); rep (i, n) cin >> x[i]; RangeEdges graph(n); rep (i, n) { auto itr = lower_bound(all(x), x[i] + a); int u = itr - x.begin(); itr = upper_bound(all(x), x[i] + b); int v = itr - x.begin(); // DEBUG(i); // DEBUG(pii(u, v)); graph.add_edge(pii(i, i + 1), pii(u, v), 1); itr = lower_bound(all(x), x[i] - b + 1); u = itr - x.begin(); itr = upper_bound(all(x), x[i] - a); v = itr - x.begin(); graph.add_edge(pii(i, i + 1), pii(u, v), 1); } // DEBUG(graph.V); uf = UnionFind(graph.V); rep (i, n) { if (not graph.used[i]) { // DEBUG(i); graph.dfs(i, i); } } map<int, int> mp; rep (i, n) { mp[uf.find(i)]++; } rep (i, n) { cout << mp[uf.find(i)] << endl; } }