Submission #652432

#TimeUsernameProblemLanguageResultExecution timeMemory
652432BlagojRadio Towers (IOI22_towers)C++17
0 / 100
13 ms2720 KiB
#include "towers.h" #include <bits/stdc++.h> using namespace std; int seg[150000]; vector<int> h; void build(int l, int r, int k) { if (l == r) { seg[k] = h[l]; } build(l, (l + r) / 2, k * 2); build((l + r) / 2 + 1, r, k * 2 + 1); seg[k] = max(seg[k * 2], seg[k * 2 + 1]); } int search(int l, int r, int i, int j, int k) { if (l > j || r < i) { return 0; } if (i <= l && r <= j) { return seg[k]; } return max(search(l, (l + r) / 2, i, j, k * 2), search((l + r) / 2 + 1, r, i, j, k * 2 + 1)); } void init(int N, std::vector<int> H) { h = H; build(0, N - 1, 1); } int max_towers(int L, int R, int D) { if (L == R) { return 1; } int height = 0, ans = 0; bool used = false; for (int i = L; i <= R; i++) { if (h[i] > height) { used = false; height = h[i]; for (int j = i + 1; j <= R; j++) { int x = search(0, R, i + 1, j - 1, 1); if ((x - h[i] >= D) && (x - h[j] >= D)) { if (!used) { ans++; used = true; } ans++; } } } } return ans; }
#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...