Submission #838627

#TimeUsernameProblemLanguageResultExecution timeMemory
838627erekleRadio Towers (IOI22_towers)C++17
23 / 100
4078 ms11572 KiB
#include "towers.h" #include <vector> #include <algorithm> #include <set> using namespace std; int n; vector<int> H; vector<pair<int, int>> byH; const int MX_N = 1e5, LG = 17; int rmq[1+LG][MX_N]; int p2[MX_N]; int rangeMax(int l, int r) { int p = p2[r-l+1]; return max(rmq[p][l], rmq[p][r-(1<<p)+1]); } bool connected(int x, int y, int d) { if (x == y) return true; if (x > y) swap(x, y); if (x+1 == y) return false; return rangeMax(x+1, y-1) - d >= max(H[x], H[y]); } void init(int N, vector<int> Hs) { for (int i = 2; i <= N; ++i) p2[i] = p2[i-1] + !(i & (i-1)); n = N, H = Hs; for (int i = 0; i < n; ++i) byH.emplace_back(H[i], i); sort(byH.begin(), byH.end()); // rmq for (int i = 0; i < n; ++i) rmq[0][i] = H[i]; for (int i = 1, p = 1; i <= LG; ++i, p <<= 1) { for (int j = 0; j < n; ++j) { if (j+p >= n) rmq[i][j] = rmq[i-1][j]; else rmq[i][j] = max(rmq[i-1][j], rmq[i-1][j+p]); } } } int max_towers(int L, int R, int D) { set<int> included; for (auto [h, i] : byH) { if (i < L || i > R) continue; set<int>::iterator it = included.lower_bound(i); if (it != included.end() && !connected(i, *it, D)) continue; if (it != included.begin() && !connected(*prev(it), i, D)) continue; included.insert(i); } return included.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...