Submission #979581

#TimeUsernameProblemLanguageResultExecution timeMemory
979581michifiedLightning Conductor (POI11_pio)C++17
100 / 100
850 ms9520 KiB
#include <bits/stdc++.h> #define mp make_pair using namespace std; int n; int solve(int h1, int i1, int h2, int i2) { int l = i2, r = n + 1, mid; while (l < r - 1) { mid = (l + r) / 2; if (h1 + sqrt(mid - i1) < h2 + sqrt(mid - i2)) r = mid; else l = mid; } return h1 + sqrt(l - i1) < h2 + sqrt(l - i2) ? l : r; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int i, cur = 0, tmp; cin >> n; vector<int> h(n), ans(n); for (i = 0; i < n; i++) cin >> h[i]; vector<pair<int, int>> hull = {mp(0, 0)}; for (i = 1; i < n; i++) { while (h[i] + sqrt(hull.back().second - i) > h[hull.back().first] + sqrt(hull.back().second - hull.back().first)) hull.pop_back(); tmp = solve(h[hull.back().first], hull.back().first, h[i], i); if (tmp == n + 1) continue; hull.push_back(mp(i, tmp)); } for (i = 1; i < n; i++) { while (cur < hull.size() - 1 and hull[cur + 1].second < i) cur++; ans[i] = max(ans[i], (int) ceil(h[hull[cur].first] + sqrt(i - hull[cur].first))); } reverse(h.begin(), h.end()); reverse(ans.begin(), ans.end()); cur = 0; hull = {mp(0, 0)}; for (i = 1; i < n; i++) { while (h[i] + sqrt(hull.back().second - i) > h[hull.back().first] + sqrt(hull.back().second - hull.back().first)) hull.pop_back(); tmp = solve(h[hull.back().first], hull.back().first, h[i], i); if (tmp == n + 1) continue; hull.push_back(mp(i, tmp)); } for (i = 1; i < n; i++) { while (cur < hull.size() - 1 and hull[cur + 1].second < i) cur++; ans[i] = max(ans[i], (int) ceil(h[hull[cur].first] + sqrt(i - hull[cur].first))); } reverse(ans.begin(), ans.end()); reverse(h.begin(), h.end()); for (i = 0; i < n; i++) cout << max(0, ans[i] - h[i]) << endl; return 0; }

Compilation message (stderr)

pio.cpp: In function 'int main()':
pio.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         while (cur < hull.size() - 1 and hull[cur + 1].second < i) cur++;
      |                ~~~~^~~~~~~~~~~~~~~~~
pio.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         while (cur < hull.size() - 1 and hull[cur + 1].second < i) cur++;
      |                ~~~~^~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...