Submission #716231

#TimeUsernameProblemLanguageResultExecution timeMemory
716231Jarif_RahmanRadio Towers (IOI22_towers)C++17
23 / 100
4074 ms4920 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; 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]; }); } int max_towers(int L, int R, int D){ set<int> s; for(int i: o){ if(i < L || i > R) continue; auto it = s.upper_bound(i); bool ok = 1; if(it != s.end() && seg.get(i+1, *it-1) < h[i]+D) ok = 0; if(it != s.begin() && seg.get(*prev(it)+1, i-1) < h[i]+D) ok = 0; if(ok) s.insert(i); } return s.size(); }
#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...