Submission #716256

#TimeUsernameProblemLanguageResultExecution timeMemory
716256Jarif_RahmanRadio Towers (IOI22_towers)C++17
17 / 100
1075 ms5044 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; struct segtree{ int k = 1; vector<int> v; segtree(int n){ while(k < n) k*=2; v.assign(2*k, 0); } void update(int i, int x){ i+=k; v[i] = x; i/=2; while(i){ v[i] = max(v[2*i], v[2*i+1]); i/=2; } } int get(int l, int r, int nd, int a, int b){ if(a > r || b < l) return 0; if(a >= l && b <= r) return v[nd]; int md = (a+b)/2; return max(get(l, r, 2*nd, a, md), get(l, r, 2*nd+1, md+1, b)); } int get(int l, int r){ if(l > r) return 0; return get(l, r, 1, 0, k-1); } }; int n; vector<int> h; segtree seg(0); vector<int> o; vector<int> diffs; void init(int _n, vector<int> _h){ swap(n, _n); swap(h, _h); seg = segtree(n); for(int i = 0; i < n; i++) seg.update(i, h[i]); for(int i = 0; i < n; i++) o.pb(i); sort(o.begin(), o.end(), [&](int a, int b){ return h[a] < h[b]; }); set<int> s; for(int i: o){ auto it = s.upper_bound(i); int x = 2e9; bool ok = 1; if(it != s.end()){ int y = seg.get(i+1, *it-1); if(y < h[i]) ok = 0; x = min(x, y-h[i]); } if(it != s.begin()){ int y = seg.get(*prev(it)+1, i-1); if(y < h[i]) ok = 0; x = min(x, y-h[i]); } if(ok) s.insert(i), diffs.pb(x); } sort(diffs.begin(), diffs.end()); } int max_towers(int L, int R, int D){ return int(diffs.size())-(lower_bound(diffs.begin(), diffs.end(), D)-diffs.begin()); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...