結果
問題 | No.1170 Never Want to Walk |
ユーザー | yasunori |
提出日時 | 2024-01-09 19:14:33 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 391 ms / 2,000 ms |
コード長 | 6,907 bytes |
コンパイル時間 | 2,667 ms |
コンパイル使用メモリ | 219,420 KB |
実行使用メモリ | 10,584 KB |
最終ジャッジ日時 | 2024-09-27 20:00:56 |
合計ジャッジ時間 | 9,452 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 4 ms
5,376 KB |
testcase_13 | AC | 4 ms
5,376 KB |
testcase_14 | AC | 4 ms
5,376 KB |
testcase_15 | AC | 4 ms
5,376 KB |
testcase_16 | AC | 4 ms
5,376 KB |
testcase_17 | AC | 4 ms
5,376 KB |
testcase_18 | AC | 4 ms
5,376 KB |
testcase_19 | AC | 4 ms
5,376 KB |
testcase_20 | AC | 3 ms
5,376 KB |
testcase_21 | AC | 4 ms
5,376 KB |
testcase_22 | AC | 4 ms
5,376 KB |
testcase_23 | AC | 4 ms
5,376 KB |
testcase_24 | AC | 4 ms
5,376 KB |
testcase_25 | AC | 3 ms
5,376 KB |
testcase_26 | AC | 4 ms
5,376 KB |
testcase_27 | AC | 382 ms
10,368 KB |
testcase_28 | AC | 380 ms
10,232 KB |
testcase_29 | AC | 391 ms
10,584 KB |
testcase_30 | AC | 388 ms
10,484 KB |
testcase_31 | AC | 379 ms
10,196 KB |
testcase_32 | AC | 368 ms
10,048 KB |
testcase_33 | AC | 378 ms
9,984 KB |
testcase_34 | AC | 377 ms
10,248 KB |
testcase_35 | AC | 372 ms
10,232 KB |
testcase_36 | AC | 370 ms
10,032 KB |
testcase_37 | AC | 374 ms
10,112 KB |
testcase_38 | AC | 384 ms
10,240 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template <typename T> using min_priority_queue = priority_queue<T,vector<T>,greater<T>>; template<typename T> void printv(vector<T> &v){ bool b = false; for(auto i : v){ if(b) cout << " "; else b = true; cout << i; } cout << endl; } int64_t rand64(){ int64_t l = rand(); int64_t r = rand(); return (l<<31)+r; } template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } template <typename T> struct monoid_min{ T val; monoid_min(){ ; } monoid_min(T x){ val = x; } monoid_min e(){ return monoid_min(numeric_limits<T>::max()); } monoid_min operator*(monoid_min other){ if(val < other.val) return monoid_min(val); return other; } bool operator==(monoid_min other){ return val == other.val; } bool operator!=(monoid_min other){ return val != other.val; } }; template <typename monoid> struct mapping_add{ monoid val; mapping_add(){ val = monoid().e(); } mapping_add(monoid x){ val = x; } mapping_add id(){ return mapping_add(); } monoid map(monoid s){ return monoid(s*val); } //写像 other*self mapping_add composition(mapping_add other){ return mapping_add(val*other.val); } bool operator==(mapping_add other){ return val == other.val; } bool operator!=(mapping_add other){ return val != other.val; } }; template <typename monoid, typename mapping> struct lazySegtree{ int sz; vector<monoid> dat; vector<mapping> lazy; lazySegtree(int n){ sz = 1; while(sz <= n) sz *= 2; dat.resize(2*sz-1, monoid().e()); lazy.resize(2*sz-1, mapping().id()); } void eval(int k, int l, int r){ if(lazy[k] != mapping().id()){ dat[k] = lazy[k].map(dat[k]); if(r - l > 1){ lazy[2*k+1] = lazy[2*k+1].composition(lazy[k]); lazy[2*k+2] = lazy[2*k+2].composition(lazy[k]); } } lazy[k] = mapping().id(); return; } void sub_apply(int a, int b, mapping f, int k, int l, int r){ eval(k, l, r); if(b <= l || r <= a) return; if(a <= l && r <= b){ lazy[k] = lazy[k].composition(f); eval(k, l, r); } else{ sub_apply(a, b, f, 2*k+1, l, (l+r)/2); sub_apply(a, b, f, 2*k+2, (l+r)/2, r); dat[k] = dat[2*k+1]*dat[2*k+2]; } return; } void apply(int a, int b, mapping f){ sub_apply(a, b, f, 0, 0, sz); return; } monoid sub_get(int a, int b, int k, int l, int r){ if(b <= l || r <= a) return monoid().e(); eval(k, l, r); if(a <= l && r <= b) return dat[k]; monoid vl = sub_get(a, b, 2*k+1, l, (l+r)/2); monoid vr = sub_get(a, b, 2*k+2, (l+r)/2, r); return vl * vr; } monoid get(int a, int b){ return sub_get(a, b, 0, 0, sz); } }; struct UF { vector<int> par; vector<int> ran; vector<int> sz; UF(int n){ par.resize(n); ran.resize(n); sz.resize(n,1); for(int i = 0; i < n; i++){ par[i] = i; } } int find(int x){ if(par[x] == x) return x; int rtn = find(par[x]); par[x] = rtn; return rtn; } void unite(int x, int y){ x = find(x); y = find(y); if(x == y) return; if(ran[x] < ran[y]){ par[x] = y; sz[y] += sz[x]; } else{ par[y] = x; sz[x] += sz[y]; if(ran[x] == ran[y]){ ran[x]++; } } } bool same(int x, int y){ return find(x) == find(y); } int siz(int x){ return sz[find(x)]; } }; bool yn(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; return b; } bool debug; bool randomInput; bool debugOutput; int numOfTestCase; using ans_type = int; void input(){ if(numOfTestCase > 1){ } if(randomInput){ } else{ } return; } void output_input(){ ; } ans_type calc(){ int N, A, B; cin >> N >> A >> B; int INF = 2001002003; vector<int> X(N+2); X[0] = -INF; X[N+1] = INF; for(int i = 1; i <= N; i++) cin >> X[i]; vector<tuple<int,int,int,int>> V(N); for(int i = 0; i < N; i++){ int x = X[i+1]; auto itr1 = lower_bound(X.begin(), X.end(), x - B); auto itr2 = prev(upper_bound(X.begin(), X.end(), x - A)); auto itr3 = lower_bound(X.begin(), X.end(), x + A); auto itr4 = prev(upper_bound(X.begin(), X.end(), x + B)); int a1 = itr1 - X.begin() - 1; int a2 = itr2 - X.begin(); int a3 = itr3 - X.begin() - 1; int a4 = itr4 - X.begin(); V[i] = {a1, a2, a3, a4}; } vector<pair<int,int>> I; for(auto[a, b, c, d] : V){ //cout << a << " " << b << endl; chmax(a, 0); chmax(b, 0); if(a == b) continue; int l, r; r = -1; if(I.size()) tie(l, r) = I[I.size()-1]; if(r <= a) I.push_back({a, b}); else I[I.size()-1].second = b; } //cout << endl; //for(auto [l, r] : I) cout << l << " " << r << endl; UF U(N); for(auto[l, r] : I){ for(int i = l; i < r-1; i++){ U.unite(i, i+1); } } for(int i = 0; i < N; i++){ auto[a, b, c, d] = V[i]; if(a >= 0 && a < b) U.unite(i, a); } vector<int> ans(N); for(int i = 0; i < N; i++) ans[i] = U.siz(i); for(auto i : ans) cout << i << endl; return ans_type(); } ans_type calc_simple(){ return ans_type(); } void output(ans_type ans){ return; } int main(){ debug = 0; randomInput = 0; debugOutput = 0; numOfTestCase = 1; srand(time(NULL)); cout << fixed << setprecision(12); if(numOfTestCase == 0) cin >> numOfTestCase; if(debug){ for(int i = 0; i < numOfTestCase; i++){ if(debugOutput) cout << string(16, '-') << endl; input(); ans_type ans = calc(); ans_type ansSimple = calc_simple(); if(ans != ansSimple){ output_input(); output(ans); output(ansSimple); } } } else{ for(int i = 0; i < numOfTestCase; i++){ input(); output(calc()); } } return 0; }